Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TeX escaping ≥ and ≤ #3444

Open
HFriberg opened this issue Feb 22, 2017 · 5 comments
Open

TeX escaping ≥ and ≤ #3444

HFriberg opened this issue Feb 22, 2017 · 5 comments

Comments

@HFriberg
Copy link

The non-strict greater than and smaller than symbols, ≥ and ≤, are not defined in the TeX builder of Sphinx. I've studied the case and found that the perhaps best solution is having these definitions in the preamble:

\\DeclareUnicodeCharacter{2265}{\\ensuremath{\\geq}}
\\DeclareUnicodeCharacter{2264}{\\ensuremath{\\leq}}

I wanted to contribute this to Sphinx, but the question is where? Should this go into the ADDITIONAL_SETTINGS of sphinx/writers/latex.py where \\nobreakspace is defined similarly, or should it rather go into sphinx/util/texescape.py where most unicode definitions seem to be?

@jfbu
Copy link
Contributor

jfbu commented Feb 22, 2017

Thanks for the suggestion ! The texescape will apply to all engines, hence is not appropriate: with xetex and luatex you can input character as is with OpenType font, even in math mode with package unicode-math.

The latex.py location could be the place for pdflatex engine. However there are many Unicode characters ;-). Hence my opinion is that this should not be incorporated to Sphinx-core. What do you think @tk0miya ?

If the document uses Unicode characters extensively it is best compiled with xelatex/lualatex and OpenType fonts. If with pdflatex user can always insert the \\DeclareUnicodeCharacter... via latex-elements's 'preamble' key in conf.py or in a use of 'inputenc' key as addition to \\usepackage[utf8]{inputenc}. (or since Sphinx 1.5 using the templating approach briefly evoked at bottom of latex customization.)

By the way I can recommend newunicodechar LaTeX package. With it you can do things like

\newunicodechar{≤}{\ensuremath{\leq}}
\newunicodechar{⩽}{\ensuremath{\leqslant}}% requires amssymb or other math font package

without needing to check a Unicode codepoint (assuming you have some way via your keyboard or copy paste to insert the character).

Note: the rendering of some glyphs may be considered language dependent. For example, French uses although 90% of people writing scientific papers have lost that memory due to the big effort to redefine \leq to be \leqslant in TeX, which they don't know how to do.

This is another reason why it complicates things to try to put such mappings in Sphinx-core.

@jfbu
Copy link
Contributor

jfbu commented Feb 22, 2017

by the way, for the specific case you mentioned you can use \\usepackage[utf8x]{inputenc} for the 'inputenc' key of latex_elements dictionary.

@jfbu
Copy link
Contributor

jfbu commented Feb 22, 2017

ah sorry, utf8x option causes \DeclareUnicodeCharacter macro to be redefined and (in my brief investigation) it then wants decimal not hexadecimal input. As Sphinx puts \\DeclareUnicodeCharacter{00A0}{\\nobreakspace} in LaTeX file this causes bug.

It appears that with utf8x, one should do \\DeclareUnicodeCharacter{160}{\\nobreakspace}.
Currently, Sphinx user must use template approach to workaround this and use utf8x option with inputenc.

@HFriberg
Copy link
Author

Thank you! I see the French redefinition is a complicating factor and will just stick to my 'preamble' key in conf.py (sorry for not mentioning that I already knew this trick).

I seem to recall horrors with utf8x (although I forgot why), but the newunicodechar package is a very nice suggestion I will make use of. Great thanks also for mentioning the experimental templating feature in tex, but I am already doing customizations via preamble commands such as:

\\providecommand*{\\DUrolestrikethrough}[1]{\\sout{#1}}

which is sufficient for my needs.

@tk0miya
Copy link
Member

tk0miya commented Feb 22, 2017

The latex.py location could be the place for pdflatex engine. However there are many Unicode characters ;-). Hence my opinion is that this should not be incorporated to Sphinx-core. What do you think @tk0miya ?

It's difficult question. Surely there are many unicode characters. so it is hard to incorporate all of them into sphinx-core.
But, as you said, these characters cause the errors with non unicode support LaTeX engines; pdflatex and platex.

So it would be nice to add the characters to texescape.py when we receive issue. I know it is not a perfect way. But it saves our time.

BTW, fundamentally, it would be nice if we move to the engines supports unicode; XeTeX, LuaTeX and upLaTeX.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants