latex inside a python virtual environment
Project description
texenv
Creates lightweight TeX virtual environments and call Python methods directly from TeX code.
Installation
texenv
is currently only supported on Windows, and requires texlive
to be installed on the system.
https://tug.org/texlive/windows.html#install
Install texenv
inside an existing Python virtual environment,
pip install texenv
To create a standalone TeX installation visible only to the current environment,
texenv init
This installs a bare-bones version of LaTeX in .venv/tex
and modifies the environment activation scripts so this TeX installation is used instead of the base installation. The console needs to be closed and re-opened for the changes to take effect.
Usage
The TeX environment supports the standard tlmgr
tool which can be used to install and update packages as normal.
tlmgr install <package name>
To write all currently installed TeX packages in the environment to a file (excluding core packages required for LaTeX to run),
texenv freeze > texrequirements.txt
To synchronize the TeX installation with the packages found in a requirements file,
texenv sync texrequirements.txt
Compiling
.tex
files can be compiled in the environment using the standard tools (i.e pdflatex
). texenv
also supports a preprocessor that can be used to call Python methods directly from TeX code. The string returned by the Python method will be inserted into the document before compilation.
Writing TeX macros in Python is much more straight forward and more versatile than writing them in TeX.
Contents of example.tex
:
\documentclass{article}
\import\pymacros_1 as \pym
\pydef\test true
\begin{document}
\pym\simple[argument1, arg2=\test]
\end{document}
Contents of pymacros_1.py
, located in the same directory as example.tex
, or in a installed module named pymacros_1
def simple(arg1: str, arg2: str = 'default') -> str:
return str(arg1) + '|' + str(arg2)
Compile on command line inside virtual environment:
texenv run example.tex
The run
command invokes the preprocessor, and then calls pdflatex
on the post-processed .tex
file. The synctex file is modified after running pdflatex
so the intermediate file is transparent to synctex.
Contents of post-processed example.tex
(located in build
folder):
\documentclass{article}
\begin{document}
argument1|true
\end{document}
VSCode Setup
texenv
is designed to work with the Latex Workshop extension in VSCode. Once the extension is installed, the following
settings should be added to the settings.json
file:
"latex-workshop.latex.tools": [
{
"name": "texenv",
"command": "texenv",
"args": [
"run", "%DOC_EXT%"
],
"env": {
"Path": "%WORKSPACE_FOLDER%/.venv/tex/bin/windows;%WORKSPACE_FOLDER%/.venv/Scripts;%PATH%"
}
},
],
"latex-workshop.view.pdf.internal.synctex.keybinding": "double-click"
License
texenv is licensed under the MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file texenv-0.0.6.tar.gz
.
File metadata
- Download URL: texenv-0.0.6.tar.gz
- Upload date:
- Size: 17.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d76238a5ea893ce2ee420746f0adf3e2e5df3b9e8346f029f4c07b047b52831b |
|
MD5 | a2091e07eb138a3a55a60fe1218e3f9d |
|
BLAKE2b-256 | ccc042b90a6d7e138a1f00f0512b6d740f463816c01284c1729b09fdb318d837 |
File details
Details for the file texenv-0.0.6-py3-none-any.whl
.
File metadata
- Download URL: texenv-0.0.6-py3-none-any.whl
- Upload date:
- Size: 18.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | be94778e39e5424e60049b165aaefb502c0d0634c6e5f813880086f1d77d1534 |
|
MD5 | bd8804958e106d1f7dfb8df378f7a627 |
|
BLAKE2b-256 | e12e10caee629199a4bd4007bea21e87a7728a1f3f9ad96a3db235b5840905c0 |