Skip to content
This repository has been archived by the owner on Jan 13, 2024. It is now read-only.

Commit

Permalink
switch to xelatex if possible
Browse files Browse the repository at this point in the history
  • Loading branch information
sdpython committed Mar 3, 2018
1 parent dab82aa commit 1c8898a
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 11 deletions.
1 change: 1 addition & 0 deletions .circleci/config.yml
Expand Up @@ -26,6 +26,7 @@ jobs:
command: |
sudo apt-get install -y texlive
sudo apt-get install -y texlive-latex-extra
sudo apt-get install -y texlive-xetex
- run:
name: Install 7z, unrar
Expand Down
2 changes: 2 additions & 0 deletions src/pyquickhelper/helpgen/post_process.py
Expand Up @@ -741,6 +741,8 @@ def clean_unicode(c):
st = st.replace("<br />", "\\\\")
st = st.replace("»", '"')
st = st.replace("\\mathbb{1}", "\\mathbf{1\\!\\!1}")
st = st.replace(
"\\documentclass[11pt]{article}", "\\documentclass[10pt]{article}")

if not doall and not latex_book:
st = st.replace(
Expand Down
40 changes: 34 additions & 6 deletions src/pyquickhelper/helpgen/process_notebooks.py
Expand Up @@ -49,6 +49,36 @@
"""


def find_pdflatex(latex_path):
"""
Returns the executable for latex.
@param latex_path path to look (only on Windows)
@return executable
.. versionadded:: 1.7
"""
if sys.platform.startswith("win"):
lat = os.path.join(latex_path, "xelatex.exe")
if os.path.exists(lat):
return lat
lat = os.path.join(latex_path, "pdflatex.exe")
if os.path.exists(lat):
return lat
raise FileNotFoundError(
"Unable to find pdflatex or xelatex in '{0}'".format(latex_path))
else:
try:
out, err = run_cmd("xelatex --help", wait=True)
if len(err) == 0:
return "xelatex"
else:
raise FileNotFoundError(
"Unable to run xelatex\n{0}".format(err))
except Exception as e:
return "pdflatex"


def process_notebooks(notebooks, outfold, build, latex_path=None, pandoc_path=None,
formats=("ipynb", "html", "python", "rst",
"slides", "pdf", "present", "github"), fLOG=fLOG, exc=True,
Expand Down Expand Up @@ -215,6 +245,7 @@ def _process_notebooks_in(notebooks, outfold, build, latex_path=None, pandoc_pat
.. versionchanged:: 1.7
Change default value of *remove_unicode_latex* to False.
Use `xelatex <https://doc.ubuntu-fr.org/xelatex>`_ if possible.
"""
from nbconvert.nbconvertapp import main as nbconvert_main
if pandoc_path is None:
Expand Down Expand Up @@ -433,10 +464,7 @@ def _process_notebooks_in(notebooks, outfold, build, latex_path=None, pandoc_pat
if compilation:
# compilation latex
if not sys.platform.startswith("win") or os.path.exists(latex_path):
if sys.platform.startswith("win"):
lat = os.path.join(latex_path, "pdflatex.exe")
else:
lat = "pdflatex"
lat = find_pdflatex(latex_path)

tex = set(_ for _ in thisfiles if os.path.splitext(
_)[-1] == ".tex")
Expand All @@ -449,7 +477,7 @@ def _process_notebooks_in(notebooks, outfold, build, latex_path=None, pandoc_pat
tex, custom_latex_processing=None, nblinks=nblinks,
remove_unicode=remove_unicode_latex, fLOG=fLOG)
# -interaction=batchmode
c = '"{0}" "{1}" -max-print-line=900 -quiet -output-directory="{2}"'.format(
c = '"{0}" "{1}" -max-print-line=900 -output-directory="{2}"'.format(
lat, tex, os.path.split(tex)[0])
fLOG("[_process_notebooks_in] ** LATEX compilation (b)", c)
if not sys.platform.startswith("win"):
Expand All @@ -463,7 +491,7 @@ def _process_notebooks_in(notebooks, outfold, build, latex_path=None, pandoc_pat
out, err = run_cmd(
c, wait=True, log_error=False, shell=sys.platform.startswith("win"),
catch_exit=True, prefix_log="[latex] ", change_path=change_path)
if out is not None and "Output written" in out:
if out is not None and ("Output written" in out or 'bytes written' in out):
# The output was produced. We ignore the return code.
fLOG(
"[_process_notebooks_in] WARNINGS: Latex compilation had warnings:", c)
Expand Down
7 changes: 2 additions & 5 deletions src/pyquickhelper/helpgen/sphinx_main_helper.py
Expand Up @@ -17,6 +17,7 @@
from ..filehelper import explore_folder_iterfile
from .utils_sphinx_doc_helpers import HelpGenException
from .post_process import post_process_latex_output
from .process_notebook import find_pdflatex

if sys.version_info[0] == 2:
from codecs import open
Expand Down Expand Up @@ -326,11 +327,7 @@ def compile_latex_output_final(root, latex_path, doall, afile=None, latex_book=F
.. versionadded:: 1.6
Parameter *remove_unicode* was added.
"""
if sys.platform.startswith("win"):
lat = os.path.join(latex_path, "pdflatex.exe")
else:
lat = "pdflatex"

lat = find_pdflatex(latex_path)
build = os.path.join(root, "_doc", "sphinxdoc", "build", "latex")
if not os.path.exists(build):
build = root
Expand Down

0 comments on commit 1c8898a

Please sign in to comment.