diff options
author | Dimitar Dimitrov <mail.mitko@gmail.com> | 2023-04-03 10:11:06 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-03 10:11:06 +0200 |
commit | be65c8313c8a2f6caaccf33da510a62005533774 (patch) | |
tree | 146810d4193384b1b45556132fe9de75bf45de7b | |
parent | 39fa276b360dc36953b3ba62e19d6a978cd5109c (diff) | |
download | sphinx-git-be65c8313c8a2f6caaccf33da510a62005533774.tar.gz |
support for imgmath_latex=tectonic (#11281)
* add rudimentary support for using tectonic with imgmath
* fix typo
* addressing PR comment
* revert changes to preview.tex_t; add dvips by default for SVG
* bugfix
-rw-r--r-- | sphinx/ext/imgmath.py | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/sphinx/ext/imgmath.py b/sphinx/ext/imgmath.py index e9de17750..34d716686 100644 --- a/sphinx/ext/imgmath.py +++ b/sphinx/ext/imgmath.py @@ -80,13 +80,17 @@ def write_svg_depth(filename: str, depth: int) -> None: def generate_latex_macro(image_format: str, - math: str, config: Config, confdir: str = '') -> str: + math: str, + config: Config, + confdir: str = '') -> str: """Generate LaTeX macro.""" variables = { 'fontsize': config.imgmath_font_size, 'baselineskip': int(round(config.imgmath_font_size * 1.2)), 'preamble': config.imgmath_latex_preamble, - 'tightpage': '' if image_format == 'png' else ',tightpage', + # the dvips option is important when imgmath_latex in ["xelatex", "tectonic"], + # it has no impact when imgmath_latex="latex" + 'tightpage': '' if image_format == 'png' else ',dvips,tightpage', 'math': math, } @@ -123,10 +127,14 @@ def compile_math(latex: str, builder: Builder) -> str: with open(filename, 'w', encoding='utf-8') as f: f.write(latex) + imgmath_latex_name = path.basename(builder.config.imgmath_latex) + # build latex command; old versions of latex don't have the # --output-directory option, so we have to manually chdir to the # temp dir to run it. - command = [builder.config.imgmath_latex, '--interaction=nonstopmode'] + command = [builder.config.imgmath_latex] + if imgmath_latex_name not in ['tectonic']: + command.append('--interaction=nonstopmode') # add custom args from the config file command.extend(builder.config.imgmath_latex_args) command.append('math.tex') @@ -134,7 +142,10 @@ def compile_math(latex: str, builder: Builder) -> str: try: subprocess.run(command, capture_output=True, cwd=tempdir, check=True, encoding='ascii') - return path.join(tempdir, 'math.dvi') + if imgmath_latex_name in ['xelatex', 'tectonic']: + return path.join(tempdir, 'math.xdv') + else: + return path.join(tempdir, 'math.dvi') except OSError as exc: logger.warning(__('LaTeX command %r cannot be run (needed for math ' 'display), check the imgmath_latex setting'), |