I, too, felt that the buttons were not correctly mapped for Retroarch (libretro) emulators so here is my fix.
I assume from your references to square and triangle that you are using a PlayStation controller but you don’t say whether it’s connected by USB or Bluetooth. For a wired (USB) PS3 controller, this is what I did. Run the command
sudo nano "/opt/retropie/emulators/retroarch/configs/Sony_PLAYSTATION(R)3_Controller.cfg"
Here, you can reassign input_b_btn, input_y_btn, input_a_btn and input_x_btn to your own preferences.
If you are connecting via bluetooth, then you should be able to find the BT config file in the /opt/retropie/emulators/retroarch/configs folder.