Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[DOC] LaTeX: fix preamble (closes #15026) #15028

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

Merged
merged 3 commits into from
Dec 4, 2019
Merged

Conversation

jfbu
Copy link
Contributor

@jfbu jfbu commented Dec 2, 2019

I tried it out only with Python 3.7.5 (CPython), Sphinx 2.2.1.

I feel --halt-on-error is better than -interaction = batchmode (anyhow this was not applied because Sphinx LaTeX Makefile changed at 1.6). In both cases latexmk exists with an error, but the former will have the error crashing the build be the last thing in the LaTeX log file.

But I separated this as a second commit so the two commits can be considered separately.

jfbu added 2 commits December 2, 2019 20:05
Memo: latex_preamble got removed from Sphinx at 1.6.1, and old
LaTeX package expdlist requires a fix else it breaks LaTeX
if a description list is in a table cell, and it causes anyhow
many LaTeX complaints about Underfull box (badness 10000).
The fix for these complaints is copied over from
scipy/scipy@c881fdea7a7ef7c518b789
and it turns out it is also a fix for the crash in case
a description list is in a table..
@mattip
Copy link
Member

mattip commented Dec 3, 2019

Trying this out, I get an error

 Package fontenc Error: Encoding file `lgrenc.def' not found

Do I have to update something in my latex/tex installation (on Ubuntu 18.04)?

@jfbu
Copy link
Contributor Author

jfbu commented Dec 3, 2019

Trying this out, I get an error

 Package fontenc Error: Encoding file `lgrenc.def' not found

@mattip The preamble which this PR activates contained the \usepackage[LGR,T1]{fontenc} which tries to load file lgrenc.def.

Additionally documentation of latex_elements['fontenc'] now says

(copied from Sphinx doc)

Prior to 2.0, Unicode Greek letters were escaped to use LaTeX math mark-up. This is not the case anymore, and the above (i.e. adding LGR) must be used (only in case of 'pdflatex' engine) if the source contains such Unicode Greek.

On Ubuntu xenial, packages texlive-lang-greek and cm-super (for the latter, only if the 'fontpkg' setting is left to its default) are needed for LGR to work. In place of cm-super one can install smaller cm-super-minimal, but it requires the LaTeX document to execute \usepackage[10pt]{type1ec} before loading fontenc. Thus, use this key with this extra at its start if needed.

(end of copied text)

Do I have to update something in my latex/tex installation (on Ubuntu 18.04)?

Yes, probably... as numpy does not modify 'fontpkg', the instructions above should apply. They cover additional LaTeX packages needed by Sphinx when detecting LGR, in particular substitutefont and textgreek packages.

Usage of this LGR is only in case the text is possibly containing Greek letters. LaTeX math mode is still something else. See the "hint" given at latex_elements['textgreek']. But this is quite possibly irrelevant to numpy docs, so a priori all you have to take care of is to make sure suitable LaTeX dependencies are available as indicated above.

@jfbu
Copy link
Contributor Author

jfbu commented Dec 3, 2019

edit: actually the numpy conf.py has

latex_elements = {
    'fontenc': r'\usepackage[LGR,T1]{fontenc}'
}

so this does not come from 'preamble' key as I erroneously indicated. The problem about missing lgrenc.def should have arisen earlier...

@jfbu
Copy link
Contributor Author

jfbu commented Dec 3, 2019

ah ok I understand, the error was masked by "batchmode" previously on your system with a missing dependency. I tried with this latex file

\documentclass{article}

\usepackage[LGRR,T1]{fontenc}

\begin{document}
coucou
\end{document}

then

$ pdflatex --interaction batchmode testbatchmode.tex
This is pdfTeX, Version 3.14159265-2.6-1.40.20 (TeX Live 2019) (preloaded format=pdflatex)
 restricted \write18 enabled.
entering extended mode

has no trace of the missing file error but

$ pdflatex --halt-on-error testbatchmode.tex
This is pdfTeX, Version 3.14159265-2.6-1.40.20 (TeX Live 2019) (preloaded format=pdflatex)
 restricted \write18 enabled.
entering extended mode
(./testbatchmode.tex
LaTeX2e <2019-10-01> patch level 3
(/usr/local/texlive/2019/texmf-dist/tex/latex/base/article.cls
Document Class: article 2019/10/25 v1.4k Standard LaTeX document class
(/usr/local/texlive/2019/texmf-dist/tex/latex/base/size10.clo))
(/usr/local/texlive/2019/texmf-dist/tex/latex/base/fontenc.sty

! Package fontenc Error: Encoding file `lgrrenc.def' not found.
(fontenc)                You might have misspelt the name of the encoding.

See the fontenc package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                              
                                                  
l.104 \ProcessOptions*
                      
!  ==> Fatal error occurred, no output PDF file produced!
Transcript written on testbatchmode.log.

@jfbu
Copy link
Contributor Author

jfbu commented Dec 3, 2019

@mattip I was going to suggest possibly dropping LGR but in fact numpy-ref.pdf needs it because of

add_newdoc('numpy', 'euler_gamma',
"""
``γ = 0.5772156649015328606065120900824024310421...``
References
----------
https://en.wikipedia.org/wiki/Euler-Mascheroni_constant
""")

If one drops LGR, then one gets while building numpy-ref.pdf:

[425]

! Package inputenc Error: Unicode character γ (U+03B3)
(inputenc)                not set up for use with LaTeX.

See the inputenc package documentation for explanation.
Type  H <return>  for immediate help.

With LGR included, the Sphinx 2.0 mechanism triggers in, and package textalpha is used which automatically tells pdflatex not to choke on γ. But then lgrenc.def is a LaTeX dependency, thus texlive-lang-greek and cm-super or cm-super-minimal on Ubuntu (see for the latter my previous quote of Sphinx docs for an extra detail)

@mattip
Copy link
Member

mattip commented Dec 3, 2019

thus texlive-lang-greek and cm-super or cm-super-minimal on Ubuntu

Thanks, that solved it. So we should mention that somewhere in our dependencies. I think the how to build docs might be appropriate.

@jfbu
Copy link
Contributor Author

jfbu commented Dec 3, 2019

@mattip The problem with such documentation is that it could be non obvious to cover all various Linux distros. Specific Sphinx LaTeX requirements are enumerated here but only mention Ubuntu.

Does it matter between requiring cm-super and cm-super-minimal? If we want to allow the latter then the latex_elements['fontpkg'] should be r'\usepackage[10pt]{type1ec}\usepackage[LGR,T1]{fontenc}'. But cm-super-minimal might be a Debian/Ubuntu thing only (sorry, I have no idea). There does not seem to be at TeXLive level itself an analogous, and I find only cm-super packaging name. On the other hand as there is thus such a TeXLive package cm-super it probably exists in all Linux distros whose LaTeX distribution is based upon upstream TeXLive.

@mattip
Copy link
Member

mattip commented Dec 3, 2019

I think it is fine to start with Ubuntu. The important thing is have some kind of indication of installation requirements, then users can adapt them to their build systems. Extra points for working fontenc into the instruction so searching the NumPy documentation for latex or fontenc will guide the user to the new instruction

@jfbu
Copy link
Contributor Author

jfbu commented Dec 3, 2019

@mattip ok, before actually pushing a commit to add such user info, one last thing. Is there any potential for Numpy docs becoming populated with Unicode apart from individual Greek or Cyrillic letters? Sphinx since 2.0.0 has built-in automatic support via pdflatex route for those (adding resp. LGR and X2 or T2A to 'fontenc' key) but this does not cover things such as Unicode math glyphs (in plain text). I have submitted a matplotlib PR to help build their PDF docs, and it is mandatory at their project to use 'xelatex' (or 'lualatex') with usage of an OpenType font such as STIX (I chose the XITS fork). Perhaps this would be appropriate in the long term for Numpy as well, and would obsolete our LGR discussion and modifies the LaTeX dependency. PS: I will be offline now for a few hours.

@mattip
Copy link
Member

mattip commented Dec 4, 2019

Let's try to keep it simple and only add the support for mathematical symbols for now, we can always revisit this in the future.

@@ -5,7 +5,7 @@ Building the NumPy API and reference docs
=========================================

We currently use Sphinx_ for generating the API and reference
documentation for NumPy. You will need Sphinx 1.8.3 <= 1.8.5.
documentation for NumPy. You will need Sphinx >= 2.0.0.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I felt bad about doing this only for latex PDF, but it seems testing (I don't know if that includes building docs, and possibly it does it only for html) goes via .circleci/config.yml which has sphinx==2.2.0

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There were problems with sphinx 2.0.0, we should document what we use in the circle CI html run: 2.2.0

You will need to have Latex installed for this.
You will need to have Latex installed for this, inclusive of support for
Greek letters. For example, on Ubuntu xenial ``texlive-lang-greek`` and
``cm-super`` are needed. Also ``latexmk`` is needed on non-Windows systems.
Copy link
Contributor Author

@jfbu jfbu Dec 4, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, the texlive-lang-greek and cm-super dependencies could be avoided via this diff

diff --git a/numpy/doc/constants.py b/numpy/doc/constants.py
index 72793e44d..fc3ca4b2c 100644
--- a/numpy/doc/constants.py
+++ b/numpy/doc/constants.py
@@ -51,7 +51,7 @@ add_newdoc('numpy', 'e',
 
 add_newdoc('numpy', 'euler_gamma',
     """
-    ``γ = 0.5772156649015328606065120900824024310421...``
+    :math:`\\gamma` ``= 0.5772156649015328606065120900824024310421...``
 
     References
     ----------

and one must (else Sphinx 2.x mechanism for Greek is triggered and there will be error about missing lgrenc.def file if texlive-lang-greek is not installed) remove LGR from latex_elements['fontenc'] configuration in doc/source/conf.py.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should document what we need to do, so either use gamma and remove LGR or leave it as-is.

@jfbu
Copy link
Contributor Author

jfbu commented Dec 4, 2019

About my comments about cm-super please take into account I don't have access to an Ubuntu box with admin rights, I can't install or remove packages for testing. I am copying over information which I established at one point in the past for the purpose of Sphinx maintenance but it may not be accurate. Generally speaking advice is that LaTeX should be installed via TeXLive and not rely on Linux distros packaging of it.

@mattip
Copy link
Member

mattip commented Dec 4, 2019

I am copying over information which I established at one point in the past for the purpose of Sphinx maintenance but it may not be accurate

I can check that it works locally on an Ubuntu machine. So we are almost there: just need to change the sphinx version to 2.2 and decide whether to use \\gamma and remove LGR.

@jfbu
Copy link
Contributor Author

jfbu commented Dec 4, 2019

and decide whether to use \\gamma and remove LGR.

Is this gamma symbol supposed to be usable by copy-paste or Numpy users use euler_gamma input? Because if rendered via math mode it will give in PDF 𝛾 i.e. Unicode hex point 1d6fe MATHEMATICAL ITALIC SMALL GAMMA.

I we use LGR, the PDF will give (at least in my testing with Skim.app on macos x) via copy paste the same as original in source i.e. γ GREEK SMALL LETTER GAMMA.

@mattip
Copy link
Member

mattip commented Dec 4, 2019

Let's just put this in as-is, we can fix up the niggle about the sphinx version and greek rendering in a subsequent PR, since the documentation building directions need some editing cleanup anyway.

@mattip mattip merged commit 4bc7eda into numpy:master Dec 4, 2019
@mattip
Copy link
Member

mattip commented Dec 4, 2019

Thanks @jfbu, looking forward to more contributions in the future.

@jfbu
Copy link
Contributor Author

jfbu commented Dec 4, 2019

@mattip thanks now lunch time :-)

@jfbu jfbu deleted the latex_fix_preamble branch December 4, 2019 20:20
jfbu added a commit to jfbu/matplotlib that referenced this pull request Dec 5, 2019
But removing enumitem package reveals a bug in expdlist. Import the fix
from the SciPy and NumPy projects.

numpy/numpy#15028
scipy/scipy@c881fde
jfbu added a commit to jfbu/matplotlib that referenced this pull request Mar 22, 2020
- remove loading of amsmath, amssymb, amsfonts (already done by
  sphinx.sty)
- remove loading of txfonts (not compatible with xetex/fontspec)
- patch old obsolete expdlist.sty
- resolve "Too deeply nested" error without using enumitem package.
  This Imports the fix already applied to NumPy and SciPy

    numpy/numpy#15028
    scipy/scipy@c881fde

- use XITS and XITS Math for wide enough Unicode coverage. As XITS has
  all the Unicode mathematical symbols needed for the section of the
  documentation related to Mathtext.
  (DejaVu Serif was missing 134 of them, and GNU FreeFont 19 of them)

  The Ubuntu package texlive-fonts-extra provides these latex dependencies.

- better looking general index in PDF documentation
- backport sphinx-doc/sphinx/pull/6888 to fix double quote issue
QuLogic pushed a commit to QuLogic/matplotlib that referenced this pull request Nov 13, 2020
But removing enumitem package reveals a bug in expdlist. Import the fix
from the SciPy and NumPy projects.

numpy/numpy#15028
scipy/scipy@c881fde
QuLogic pushed a commit to QuLogic/matplotlib that referenced this pull request Dec 17, 2020
But removing enumitem package reveals a bug in expdlist. Import the fix
from the SciPy and NumPy projects.

numpy/numpy#15028
scipy/scipy@c881fde
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging this pull request may close these issues.

2 participants