ObsiTex is a Python package that automates the conversion of Obsidian Markdown files and folders into structured LaTeX documents. Designed for researchers, students, and technical writers, it ensures a seamless transition from Markdown to a fully formatted LaTeX file, preserving document structure and references.
- Eliminates manual LaTeX formatting for Markdown-based notes.
- Preserves headings, lists, equations, figures, citations, and more.
- Supports entire folders, making it ideal for research papers and dissertations.
- Uses Jinja2 templates, allowing full customization of the LaTeX output.
To install ObsiTex, use pip:
pip install obsitex
Convert an Obsidian folder into a LaTeX document:
obsitex --input "My Obsidian Folder" --main-tex output.tex
Convert a single Markdown file:
obsitex --input "My Note.md" --main-tex output.tex
Use ObsiTex as a Python library:
from obsitex import ObsidianParser
parser = ObsidianParser()
parser.add_dir("My Obsidian Folder")
latex_content: str = parser.to_latex()
Most of the standard Markdown elements are supported, including:
- Equations (inline and block)
- Figures (with captions and metadata)
- Tables (with captions and metadata)
- Citations (using BibTeX references)
- Headings (up to level 6, but can be customized)
- Lists (enumerated and bulleted)
- Blockquotes
- Standard text formatting (bold, italics, code blocks, etc.)
This system works best if used with the Obsidian plugin obsidian-citation-plugin, which allows for the easy insertion of citations in markdown files. The citations must be in the format [[@citekey]]
, where citekey
is the key of the reference in the BibTeX file.
Use the following syntax to create a figure in Obsidian:
> [!figure] Caption for the figure
> ![[example-image.png]]
> %%
> width: 0.5
> label: example-image
> position: H
> %%
Which may be broken down as follows:
Caption for the figure
: The caption for the figure.![[example-image.png]]
: The path to the image, if a figure is present, then the graphics folder must be provided.%%
: This is a Obsidian comment, which allows for additional metadata to be added to the figure, without affecting the markdown rendering in Obsidian. If not present, default values will be used. This content must be YAML formatted.
Use the following syntax to create a table in Obsidian:
> [!table] Random Table
> | Name | Age | City |
> |-------|-----|----------|
> | Alice | 25 | New York |
> | Bob | 30 | London |
> | Eve | 28 | Tokyo |
> %%
> prop: value
> %%
This allows for the creation of tables in markdown, thus easily rendered in Obsidian, and then converted to LaTeX.
Similarly to figures, metadata can be added to the table, in order to customize the rendering of the table in LaTeX. This content must be YAML formatted.
These are custom blocks, thus won't have styling in Obsidian unless explictly defined in a CSS snippet. You can define the styling by following the instructions in the Obsidian documentation.
- Motivation Letter: Single file motivation letter with no citations or figures, one of the simplest use cases.
- Sock Research Paper: Single file research paper on socks with authors, affilitions, abstract, and content defined entirely in markdown.
- MSc Dissertation on Ducks: Folder containing a MSc thesis on ducks, with multiple markdown files under a common folder, and an
Index.md
file defining the hierarchy of the thesis.
These samples were all converted to PDF using XeLaTeX, and the output files are available in the output
folder of each sample.
Charlie Beckett is applying for a position at Willy Wonka's Chocolate Factory, and has written a motivation letter in markdown. Of course this isn't the only factory he's applying to, so he wants the letter to be easily customizable for other applications.
Unlike the other examples, this example doesn't require a BibTex file or graphics folder, as it doesn't contain any citations or figures. The LaTeX file can be generated by:
cd samples/motivation-letter;
obsitex --input "Motivation Letter.md" \
--template template.tex \
--main-tex output/main.tex ;
Made up authors from the International Sock Research Institute, Textile Innovation Center, and Academy of Footwear Sciences have written a research paper on socks that was entirely developed in markdown. The authors now want to convert this document to pdf in order to submit it to a conference.
The LaTeX file and correspondings Bib file can be generated by:
cd samples/sock-research-paper;
obsitex --input "The Evolution of Socks.md" \
--graphics ../images \
--bibtex ../shared-references.bib \
--template template.tex \
--main-tex output/main.tex \
--main-bibtex output/main.bib ;
An unknown author has written a MSc thesis on ducks, and has organized the thesis in multiple markdown files under a common folder. The author now wants to convert this thesis to a single LaTeX file.
The folder structure is as follows:
obsidian-folder
├── Findings and Implications
│ ├── Conclusion
│ │ └── Conclusion.md
│ ├── Findings and Discussion
│ │ ├── Economic Viability.md
│ │ ├── Findings and Discussion.md
│ │ ├── Social and Cultural Implications.md
│ │ └── Urban Planning and Infrastructure Challenges.md
│ └── Findings and Implications.md
├── Index.md
└── Introduction and Background
├── Introduction
│ └── Introduction.md
├── Introduction and Background.md
├── Literature Review
│ └── Literature Review.md
└── Methodology
└── Methodology.md
8 directories, 11 files
Index.md
defines the entry point for obsitex
, by creating links between the different sections of the thesis, in the target order. In this example, the Index.md
file is as follows:
[[Introduction and Background]]
[[Findings and Implications]]
Thus, the first part will be the Introduction and Background
part, followed by the Findings and Implications
part. The LaTeX file and correspondings Bib file can be generated by:
cd samples/msc-dissertation;
obsitex --input obsidian-folder \
--graphics ../images \
--bibtex ../shared-references.bib \
--template template.tex \
--main-tex output/main.tex \
--main-bibtex output/main.bib ;
Learn how to create parsers for custom blocks in the samples/byob
folder. This will allow you to add custom blocks to the parser, and thus customize the LaTeX output to your needs.
This example adds support for line breaks and warnings in the LaTeX output, by creating custom blocks for these elements.
You can only use this feature if using the python library. To run this sample, use the following command:
cd samples/byob;
python run_sample.py;
This work was inspired by:
- Obsidian Citation Plugin – For enabling seamless reference management within Obsidian.
- Alejandro Daniel Noel – His work served as an initial and valuable basis for this project.
- dbt – For giving me the idea of using Jinja2 templates for LaTeX conversion.
This project is licensed under the MIT License.