mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
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
This commit is contained in:
@@ -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'),
|
||||
|
||||
Reference in New Issue
Block a user