docs: add teaching examples and video project
This commit is contained in:
parent
e93bc20b0a
commit
7a06f94577
42 changed files with 8022 additions and 0 deletions
43
show/video/tex_environment.py
Normal file
43
show/video/tex_environment.py
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
"""Use system TeX Live, or an explicitly configured local unpacked installation."""
|
||||
from pathlib import Path
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
|
||||
HERE = Path(__file__).resolve().parent
|
||||
|
||||
|
||||
def prepare_tex(env):
|
||||
env = dict(env)
|
||||
if shutil.which('latex', path=env['PATH']) and shutil.which('dvisvgm', path=env['PATH']):
|
||||
return env
|
||||
root = Path(env.get('SLIME_TEX_ROOT', HERE / '.native/texlive')).resolve()
|
||||
if not (root/'usr/bin/pdftex').is_file():
|
||||
raise RuntimeError('需要 LaTeX / dvisvgm。Ubuntu: sudo apt install texlive-latex-extra dvisvgm')
|
||||
dist = root/'usr/share/texlive/texmf-dist'
|
||||
formats = root/'formats'
|
||||
formats.mkdir(exist_ok=True)
|
||||
env.update({
|
||||
'PATH': str(root/'usr/bin')+os.pathsep+env['PATH'],
|
||||
'LD_LIBRARY_PATH': str(root/'usr/lib/x86_64-linux-gnu')+os.pathsep+env.get('LD_LIBRARY_PATH', ''),
|
||||
'TEXMFCNF': str(dist/'web2c'),
|
||||
'TEXMFROOT': str(root/'usr/share/texlive'),
|
||||
'TEXMFDIST': str(dist),
|
||||
'TEXMF': '{'+str(dist)+','+str(root/'usr/share/texmf')+'}',
|
||||
'TEXMFVAR': str(root/'var'),
|
||||
'TEXMFCONFIG': str(root/'config'),
|
||||
'TEXMFHOME': str(root/'texmf-home'),
|
||||
'TEXFORMATS': str(formats)+'//:',
|
||||
})
|
||||
gs_roots = sorted((root/'usr/share/ghostscript').glob('*'))
|
||||
if gs_roots:
|
||||
gs = gs_roots[-1]
|
||||
env['GS_LIB'] = os.pathsep.join(str(p) for p in (
|
||||
gs/'Resource/Init', gs/'lib', gs/'Resource/Font',
|
||||
root/'usr/share/fonts/type1/urw-base35'))
|
||||
if not (formats/'latex.fmt').is_file():
|
||||
subprocess.run(['mktexlsr', str(dist), str(root/'usr/share/texmf')], env=env, check=True)
|
||||
subprocess.run(['pdftex', '-ini', '-etex', '-interaction=nonstopmode', '-halt-on-error',
|
||||
'-jobname=latex', '-progname=latex', 'latex.ini'],
|
||||
cwd=formats, env=env, check=True)
|
||||
return env
|
||||
Loading…
Add table
Add a link
Reference in a new issue