A lightweight, command-line tool for instantly compiling and previewing LaTeX snippets. This tool provides a simple REPL (Read-Eval-Print Loop) in your terminal, which calls the pdflatex compiler and displays the output in a clean, borderless pop-up window.
It's designed for quickly testing equations, formatting, or small pieces of LaTeX without the overhead of a full IDE.
- Interactive CLI: A simple and familiar command-line prompt for entering LaTeX code.
- Instant Pop-up Preview: Renders your code in a borderless window that appears over your terminal for quick viewing.
- Direct PDF Rendering: Uses the high-quality PyMuPDF library to render the PDF directly to an image in memory, with no intermediate files.
- Copy Functionality: Right-click the preview window to copy the underlying, extracted text to your clipboard.
- Minimal Dependencies: Relies only on your existing TeX distribution and a few Python packages.
- Automatic Cleanup: Automatically creates and deletes temporary build files (
.log,.aux, etc.) in alatex_tempsubdirectory.
Before you begin, ensure you have the following installed:
- Conda: An installation of Anaconda or Miniconda.
- TeX Distribution: A working LaTeX installation such as TeX Live, MiKTeX, or MacTeX. The
pdflatexcommand must be available in your system's PATH. You can check this by opening a terminal and typingpdflatex --version.
Follow these steps to set up the project using conda.
Navigate to your project directory (where you have latex_cli.py and requirements.txt). You can create a new conda environment and install all required packages in a single step using the requirements.txt file.
conda create --name latex_cli --file requirements.txtThis command creates a new, isolated environment named latex_cli and installs all the packages listed in the requirements file.
Once the environment is created, activate it:
conda activate latex_cliYour terminal prompt should now show (latex_cli) at the beginning, indicating the environment is active.
To run the script easily from any terminal with a simple command like latex-cli, you should create a PowerShell script launcher. This also ensures the script is executed correctly using the Python interpreter from your conda environment.
A PowerShell script is a plain text file that contains a sequence of commands.
- Create a dedicated folder for your scripts. A good practice is to create a folder like
C:\Scripts. - Find your Python interpreter's full path. With your
condaenvironment active, run the commandwhere python. It will show you the path. Copy the one that points inside yourlatex_cliConda environment folder. - Create a new text file inside
C:\Scriptsand name itlatex-cli.ps1. - Edit
latex-cli.ps1and add the following lines, replacing the paths with the full paths to your Python interpreter and yourlatex_cli.pyscript.
Example:
& "C:/Users/marti/miniconda3/envs/latex_cli/python.exe" "C:/Users/marti/repositories/latex-cli/latex_cli.py" @ArgsThis final step makes your latex-cli command globally accessible from any terminal.
- Press the Windows key and type
env. - Select "Edit the system environment variables".
- In the System Properties window, click the "Environment Variables…" button.
- In the top section ("User variables"), find and select the
Pathvariable, then click "Edit…". - Click "New" and add the path to the folder where you saved
latex-cli.ps1(e.g.,C:\Scripts). - Click "OK" on all windows to save.
- Important: Close and re-open any terminal windows for the PATH changes to take effect.
- Run the tool by simply typing
latex-cliin the terminal and pressing Enter. - You will see the
>>>prompt. Type or paste your LaTeX code. Press Enter for new lines. - When you are finished, type
:con a new line and press Enter to compile. - A borderless preview window will pop up.
- Right-click the preview to open a context menu to copy the text.
- Press the
Esckey to close the preview window.
- To exit the CLI, press
Ctrl+C.