Punctuation and symbols like # and + have no intrinsic directionality; they use the one in effect in the surrounding context.
In your case, default language is Persian. Consequently, # and + behave RTL.
C++ or C# are not seen as words, but as a “latin” word C (thus LTR) with punctuation. You have in fact 2 sequences and the result is as expected. To get the usual C++ formatting, you must tell LO Writer that the whole sequence is LTR.
You do that with a character style. Create one you’ll call Technical. In the Font
tab, force Language to None from the drop-down menu (or English in case it doesn’t work as expected – None is better because it also disables spell-checking, which is preferable for acronyms).
After that, select all your LTR sequences and give them character style Technical. The important point is to select together C and the symbols so that it is seen as a single sequence.
To show the community your question has been answered, click the ✓ next to the correct answer, and “upvote” by clicking on the ^ arrow of any helpful answers. These are the mechanisms for communicating the quality of the Q&A on this site. Thanks!
EDIT 2018-11-5 (after discussion with @Ali Baghernejad)
The cause seems to be a symbol (# or +) at the boundary between RTL and LTR text. This symbol, which can be used in any language, adopts directionality of its context. Here we have mixed context and tie is resolved in favour of “main” context, i.e. Persian because it is the document language.
Forcing language through a character style proves inoperative because CTL styles seems to decide on which part to use (Western or CTL) based on the current character. Here, + or # have no intrinsic directionality and we revert to the context (see previous argument).
The only way to force directionality is to add LTR character around the problematic sequence. C++ is typed C++a: now we have an LTR run but an extra a. This extra a is formatted Hidden so that it does not display.
This is an ugly workaround. There should be a way to tell LO Writer we want an LTR sequence (or RTL when writing Western), no matter the internal Writer rules, i.e. unconditionally force directionality.
I filed a bug as tdf#121182 (closed because it is intended behaviour; work around with explicit directionality marks)
EDIT 2018-11-6 after information from the bug site
Completely forgotten about U+202A to U+202C (bidirectionality control characters), sorry for the fuss.
I had a look to the sample file with bidirectionality controls addes attached to the bug report. It matches the required, but from a user perspective, I could not find a way to edit these controls. Backspace
or Delete
do not seem to act upon them. Instead, the erase the nearest graphic character. Consequently, you can’t manage easily the marks, other than selecting a wider sequence, erasing it and retyping the missing part.
This is not user-friendly. Have I missed something?
EDIT 2018-11-7
Feature request submitted as tdf#121256: provide visual feedback for directional marks, but i may be some time, if any, before it is implemented. Marked as duplicate of tdf#58434.