- ;; If the character is one of LRE, LRO, RLE, RLO, it will
- ;; start a directional embedding, which could completely
- ;; disrupt the rest of the line (e.g., RLO will display the
- ;; rest of the line right-to-left). So we put an invisible
- ;; PDF character after these characters, to end the
- ;; embedding, which eliminates any effects on the rest of the
- ;; line.
- (pdf (if (memq char '(?\x202a ?\x202b ?\x202d ?\x202e))
- (propertize (string ?\x202c) 'invisible t)
- ""))
+ (bidi-fixer
+ (cond ((memq char '(?\x202a ?\x202b ?\x202d ?\x202e))
+ ;; If the character is one of LRE, LRO, RLE, RLO, it
+ ;; will start a directional embedding, which could
+ ;; completely disrupt the rest of the line (e.g., RLO
+ ;; will display the rest of the line right-to-left).
+ ;; So we put an invisible PDF character after these
+ ;; characters, to end the embedding, which eliminates
+ ;; any effects on the rest of the line.
+ (propertize (string ?\x202c) 'invisible t))
+ ;; Strong right-to-left characters cause reordering of
+ ;; the following numerical characters which show the
+ ;; codepoint, so append LRM to countermand that.
+ ((memq (get-char-code-property char 'bidi-class) '(R AL))
+ (propertize (string ?\x200e) 'invisible t))
+ (t
+ "")))