Pedro Andres Aranda Gutierrez <[email protected]> writes: > More facts about why lualatex-math vs unicode-math... > > When I use fontspec+unicode-math with lualatex, what I see is the following > [image: image.png] > Look at the outline, please. > Now, replacing unicode-math with lualatex-math: > [image: image.png] > The outline is not perfect, but certainly 'better' (if you understand what > I mean).
Well. That's far from "didn't generate a PDF".
I also observed that the outline has issues with math.
I feel like you are trying to find a workaround for something that can
be fixed. Try the attached file and remember that we have
`org-latex--section-backend' where we can program the same behavior.
Here is what I got from LLM (this time, it was a good response)
The following
\section[$\backslash$\texorpdfstring{\(\psi\)}{psi} should
wrap]{$\backslash$\texorpdfstring{\(\phi\)}{phi} wraps}
this does not seem to work in lualatex. I get
灳椠 should wrap
# LLM response
What you are seeing is a double round-trip:
1. The optional short title “=$\backslash\texorpdfstring{(\psi)}{psi} should
wrap=” is processed by LaTeX first.
2. =\backslash= expands to =\textbackslash{}= and finally to a text-mode
backslash character (U+005C).
3. When hyperref converts the bookmark string to PDFDocEncoding or UTF-16 it
receives a literal backslash, followed immediately by the math command =\psi=.
PDF bookmarks do not understand math, so the character produced in position π
comes out of the encoding tables as the Unicode code-point π, and π is what you
get in the encoding tables as “灳” … when it is actually meant to remain as
literal text, you must keep it away from math mode.
With pdfTeX this accidently looks “right” because pdfTeX bookmarks use an old
8-bit PDFDocEncoding table; with Lua- and Xe-TeX (=unicode= option) the output
is shown in UTF-16 and suddenly every 8-bit character is visible.
Fix: keep the bookmark text completely free of math mode or any macro that
hyperref must expand in an expansion-only context:
#+begin_src latex
\section[\textbackslash psi should wrap]{% <-- printable part for the outline
$\backslash\phi$ wraps% <-- printed heading
}
#+end_src
or, if you really want the Greek letter in the outline, supply the /Unicode/
character directly:
#+begin_src latex
\section[\textbackslash ψ should wrap]% literal ψ (U+03C8)
{$\backslash\phi$ wraps}
#+end_src
and, if you want exactly the same text as in the full heading, protect the math
or let =\texorpdfstring= replace the whole fragment:
#+begin_src latex
\section[\texorpdfstring{\textbackslash\ensuremath{\psi}}{\textbackslash psi}
should wrap]%
{$\backslash\phi$ wraps}
#+end_src
Remember: anything that appears in the optional short-title argument must be
either
- ordinary text that can be converted to Unicode, or
- inside =\texorpdfstring= with the /second/ argument being exactly the
plain-text you want in the outline.
Using =\texorpdfstring= inside the optional argument itself fails because
hyperref tries to expand it once more and sees the literal =\backslash=
again—hence the garbled result you observed.
bug.tex
Description: TeX document
bug.pdf
Description: Adobe PDF document
-- Ihor Radchenko // yantar92, Org mode maintainer, Learn more about Org mode at <https://orgmode.org/>. Support Org development at <https://liberapay.com/org-mode>, or support my work at <https://liberapay.com/yantar92>
