Skip to content

Build: remove pdflatex support #9967

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 5 commits into from
Feb 7, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions docs/user/guides/pdf-non-ascii-languages.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ Sphinx PDFs with Unicode

Sphinx offers different `LaTeX engines`_ that have better support for Unicode characters
and non-European languages like Japanese or Chinese.
By default Sphinx uses ``pdflatex``,
which does not have good support for Unicode characters and may make the PDF builder fail.
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we keep "By default, Sphinx uses latexmk <https://mg.readthedocs.io/latexmk.html>_" or something similar?

I'm not sure how it affects Unicode characters, so seems good to delete.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, latexmk is the good one to deal with Unicode characters. That's why I deleted the sentence completely.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I was thinking that it's nice to inform people about the default builder in case they need to troubleshoot something.


.. _LaTeX engines: http://www.sphinx-doc.org/en/master/usage/configuration.html#confval-latex_engine

Expand All @@ -17,7 +15,7 @@ to modify Sphinx and Read the Docs behavior to make your documentation to build

For docs that are not written in Chinese or Japanese,
and if your build fails from a Unicode error,
then try ``xelatex`` as the ``latex_engine`` instead of the default ``pdflatex`` in your ``conf.py``:
then try ``xelatex`` as the ``latex_engine`` in your ``conf.py``:

.. code-block:: python

Expand Down
92 changes: 1 addition & 91 deletions readthedocs/doc_builder/backends/sphinx.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,38 +331,6 @@ def sphinx_parallel_arg(self):
return ['-j', 'auto']
return []

def venv_sphinx_supports_latexmk(self):
"""
Check if ``sphinx`` from the user's venv supports ``latexmk``.

If the version of ``sphinx`` is greater or equal to 1.6.1 it returns
``True`` and ``False`` otherwise.

See: https://www.sphinx-doc.org/en/master/changes.html#release-1-6-1-released-may-16-2017
"""

command = [
self.python_env.venv_bin(filename='python'),
'-c',
(
'"'
'import sys; '
'import sphinx; '
'sys.exit(0 if sphinx.version_info >= (1, 6, 1) else 1)'
'"'
),
]

cmd_ret = self.run(
*command,
bin_path=self.python_env.venv_bin(),
cwd=self.project_path,
escape_command=False, # used on DockerBuildCommand
shell=True, # used on BuildCommand
record=False,
)
return cmd_ret.exit_code == 0


class HtmlBuilder(BaseSphinx):
relative_output_dir = "_readthedocs/html"
Expand Down Expand Up @@ -543,12 +511,7 @@ def build(self):
raise BuildUserError("No TeX files were found.")

# Run LaTeX -> PDF conversions
# Build PDF with ``latexmk`` if Sphinx supports it, otherwise fallback
# to ``pdflatex`` to support old versions
if self.venv_sphinx_supports_latexmk():
success = self._build_latexmk(self.project_path)
else:
success = self._build_pdflatex(tex_files)
success = self._build_latexmk(self.project_path)

self._post_build()
return success
Expand Down Expand Up @@ -620,59 +583,6 @@ def _build_latexmk(self, cwd):

return cmd_ret.successful

def _build_pdflatex(self, tex_files):
pdflatex_cmds = [
['pdflatex', '-interaction=nonstopmode', tex_file]
for tex_file in tex_files
] # yapf: disable
makeindex_cmds = [
[
"makeindex",
"-s",
"python.ist",
"{}.idx".format(
os.path.splitext(
os.path.relpath(tex_file, self.absolute_output_dir)
)[0],
),
]
for tex_file in tex_files
] # yapf: disable

if self.build_env.command_class == DockerBuildCommand:
latex_class = DockerLatexBuildCommand
else:
latex_class = LatexBuildCommand
pdf_commands = []
for cmd in pdflatex_cmds:
cmd_ret = self.build_env.run_command_class(
cls=latex_class,
cmd=cmd,
cwd=self.absolute_output_dir,
warn_only=True,
)
pdf_commands.append(cmd_ret)
for cmd in makeindex_cmds:
cmd_ret = self.build_env.run_command_class(
cls=latex_class,
cmd=cmd,
cwd=self.absolute_output_dir,
warn_only=True,
)
pdf_commands.append(cmd_ret)
for cmd in pdflatex_cmds:
cmd_ret = self.build_env.run_command_class(
cls=latex_class,
cmd=cmd,
cwd=self.absolute_output_dir,
warn_only=True,
)
pdf_match = PDF_RE.search(cmd_ret.output)
if pdf_match:
self.pdf_file_name = pdf_match.group(1).strip()
pdf_commands.append(cmd_ret)
return all(cmd.successful for cmd in pdf_commands)

def _post_build(self):
"""Internal post build to cleanup PDF output directory and leave only one .pdf file."""

Expand Down
10 changes: 0 additions & 10 deletions readthedocs/projects/tests/test_build_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -718,16 +718,6 @@ def test_build_commands_executed(
),
# NOTE: pdf `mv` commands and others are not here because the
# PDF resulting file is not found in the process (`_post_build`)
mock.call(
mock.ANY,
"-c",
'"import sys; import sphinx; sys.exit(0 if sphinx.version_info >= (1, 6, 1) else 1)"',
bin_path=mock.ANY,
cwd=mock.ANY,
escape_command=False,
shell=True,
record=False,
),
mock.call(
mock.ANY,
"-m",
Expand Down