It helps to think of it as all the steps that would be taken by your broker.
Say on a transfer you realize the gains:
plugin "beancount.plugins.auto"
2024-01-01 * "Add cash"
Income:Misc
Assets:CA:Brokerage:USAccount:Cash 1000.00 USD
2024-01-01 * "Buy BMO in US"
Assets:CA:Brokerage:USAccount:BMO 2 BMO {90.00 USD}
Assets:CA:Brokerage:USAccount:Cash
2024-02-18 * "Sell BMO, realized gain"
Assets:CA:Brokerage:USAccount:BMO -2 BMO {90.00 USD} @ 94.19 USD
Assets:CA:Brokerage:USAccount:Cash 2*94.19 USD
Income:CA:Brokerage:USAccount:PnL
2024-02-18 * "Transfer cash equivalent"
Assets:CA:Brokerage:USAccount:Cash -2*94.19 USD
Assets:CA:Brokerage:CanadianAccount:Cash 2*127.03 CAD @ USD
2024-02-18 * "Sell BMO, realized gain"
Assets:CA:Brokerage:CanadianAccount:Cash -2*127.03 CAD
Assets:CA:Brokerage:CanadianAccount:BMO +2 BMO {127.03 CAD}
It's not super convenient, but you can compress those last three transactions to
2024-02-18 * "Sell BMO, realized gain"
Assets:CA:Brokerage:USAccount:BMO -2 BMO {90.00 USD} @ 94.19 USD
Income:CA:Brokerage:USAccount:PnL -8.38 USD
Assets:CA:Brokerage:CanadianAccount:BMO +2 BMO {127.03 CAD}
Assets:CA:Brokerage:CanadianAccount:Cash 2*127.03 CAD @ USD
Assets:CA:Brokerage:CanadianAccount:Cash -2*127.03 CAD
If you prefer to provide the exchange rate instead it can fill in the P/L:
2024-02-18 * "Sell BMO, realized gain"
Assets:CA:Brokerage:USAccount:BMO -2 BMO {90.00 USD} @ 94.19 USD
Income:CA:Brokerage:USAccount:PnL
Assets:CA:Brokerage:CanadianAccount:BMO +2 BMO {127.03 CAD}
Assets:CA:Brokerage:CanadianAccount:Cash 2*127.03 CAD @ 0.74147 USD
Assets:CA:Brokerage:CanadianAccount:Cash -2*127.03 CAD
Granted it could be better, but it's possible.
Thankfully you probably don't have a ton of these...
(You could automate the generation of these with a plugin if you do.)