Skip to main content

Convert Markdown (.md) files to PDF ...

Project description

md2ltx

A command-line tool for converting Markdown to PDF via Pandoc and LaTeX. Requires a pip virtual environment in Ubuntu/ Debian based OS.

1. Installation

pip install md2ltx; md2ltx --install_dependencies

Usage

md2ltx [source.md] [output.pdf] [--open] [--help]

Positional Arguments

source_file
Path to the input Markdown (.md) file.

output_pdf (optional)
Path to the output PDF file. If omitted, a default name is derived from the source file, and the working directory is assumed to be the path.

Optional Switches

--open
Open the resulting PDF in the system’s default viewer.

--template <template_name>
Specify a built-in templates by name. Available templates: “two-column”).

--help
Show this help message and exit.

2. Templates

md2ltx supports injecting Markdown content into a LaTeX “template” that defines the overall look and structure of the PDF.

You can choose one of the built-in templates: "two-column". Using the “--template” flag tells Pandoc to load and apply that LaTeX template. Inside the template, Pandoc replaces special variables like $title$, $author$, $date$, and $body$ with metadata and the converted Markdown content.

Specifying Title, Author, and Date

Pandoc reads title, author, and date from the YAML metadata block at the top of your Markdown file. For example:

---
title: "My Awesome Title"
author: "John Doe"
date: "October 4, 2023"
---

# Sample Document

This is a **Markdown** document to test `compile_markdown_to_pdf` from `main.py`.

## Advantages of Markdown

- Easy to write
- Human-readable
- Widely supported

## Conclusion

Markdown is fantastic!

Pandoc will inject your Markdown content where $body$ is defined, and the YAML metadata (title, author, date) will appear in your final PDF, as below.

\documentclass[twocolumn]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}

\usepackage[unicode=true]{hyperref}
\providecommand{\tightlist}{
  \setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}
}

\title{$title$}
\author{$author$}
\date{$date$}

\begin{document}
\maketitle

$body$

\end{document}

3. General Pandoc Tranformations

md2ltx uses Pandoc to transform Markdown files into LaTeX, which pdflatex then uses to generate a final PDF. This workflow supports most of Markdown’s core syntax plus many Pandoc extensions. Below is a high-level overview of how Pandoc typically converts various Markdown constructs into LaTeX. For full details, refer to Pandoc’s official documentation.


3.1. Headings

Markdown

# Heading 1  
## Heading 2  
### Heading 3

Pandoc → LaTeX

\section{Heading 1}  
\subsection{Heading 2}  
\subsubsection{Heading 3}

Pandoc chooses \section, \subsection, etc. based on the heading level. It also supports underline-style Markdown headings with “===” or “---” for level-one and level-two headings.


3.2. Emphasis & Strong Emphasis

Markdown

*emphasis* or _emphasis_  
**strong emphasis** or __strong emphasis__

Pandoc → LaTeX

\emph{emphasis}  
\textbf{strong emphasis}

3.3. Inline Code

Markdown

`inline code`

Pandoc → LaTeX

\texttt{inline code}

3.4. Code Blocks

Markdown (fenced)

```  
a = 1  
b = 2  
```

Pandoc → LaTeX (by default)

\begin{verbatim}  
a = 1  
b = 2  
\end{verbatim}

With certain options, Pandoc can use different LaTeX environments (e.g., listings).


3.5. Lists

Unordered (Markdown)

- item 1  
- item 2  
- item 3

Pandoc → LaTeX

\begin{itemize}  
\item item 1  
\item item 2  
\item item 3  
\end{itemize}

Ordered (Markdown)

1. item 1  
2. item 2

Pandoc → LaTeX

\begin{enumerate}  
\item item 1  
\item item 2  
\end{enumerate}

3.6. Links & Images

Link (Markdown)

[Pandoc](https://pandoc.org)

Pandoc → LaTeX

\href{https://pandoc.org}{Pandoc}

Image (Markdown)

![Alt text](image.png)

Pandoc → LaTeX

\includegraphics{image.png}

By default, \includegraphics is placed without floats. You can add captions or figure environments using extended syntax or metadata.


3.7. Blockquotes

Markdown

> This is a blockquote.

Pandoc → LaTeX

\begin{quote}  
This is a blockquote.  
\end{quote}

3.8. Horizontal Rules

Markdown

---  
***  
___

Pandoc → LaTeX

\hrule

3.9. Footnotes (Pandoc Extension)

Markdown

This is some text with a footnote.[^1]

[^1]: This is the footnote text.

Pandoc → LaTeX

This is some text with a footnote.\footnote{This is the footnote text.}

3.10. Tables

Markdown (simple pipe table)

| Column1 | Column2 |  
|---------|---------|  
| Val1    | Val2    |  
| Val3    | Val4    |

Pandoc → LaTeX

\begin{table}  
\centering  
\begin{tabular}{ll}  
\hline  
Column1 & Column2 \\  
\hline  
Val1    & Val2    \\  
Val3    & Val4    \\  
\hline  
\end{tabular}  
\end{table}

3.11. Math & LaTeX Blocks

Inline Math

$E = mc^2$

Pandoc → LaTeX

\(E = mc^2\)

Display Math

$$  
E = mc^2  
$$

Pandoc → LaTeX

\[  
E = mc^2  
\]

3.12. Citations & Bibliographies

Pandoc can handle citations if you provide a bibliography file. A reference like [@smith2009] can become \cite{smith2009} or \autocite depending on the style and Pandoc’s command-line options.


3.14. Raw LaTeX

Pandoc passes raw LaTeX through if you’re converting to LaTeX or PDF. For example:

\newpage

remains \newpage in the output.


Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

md2ltx-0.0.16.tar.gz (8.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

md2ltx-0.0.16-py3-none-any.whl (11.3 kB view details)

Uploaded Python 3

File details

Details for the file md2ltx-0.0.16.tar.gz.

File metadata

  • Download URL: md2ltx-0.0.16.tar.gz
  • Upload date:
  • Size: 8.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for md2ltx-0.0.16.tar.gz
Algorithm Hash digest
SHA256 8c258f1040a2b3cd1b8468319b02163fc48200300c4de31ec22003956445d7c0
MD5 11369ab2df92b56982d30f0d40584457
BLAKE2b-256 5dc8a17d21f99bcd60383d1e75dbce8d35a6d3a155e81f5067879746050b6a90

See more details on using hashes here.

File details

Details for the file md2ltx-0.0.16-py3-none-any.whl.

File metadata

  • Download URL: md2ltx-0.0.16-py3-none-any.whl
  • Upload date:
  • Size: 11.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for md2ltx-0.0.16-py3-none-any.whl
Algorithm Hash digest
SHA256 e540d2c2b986449babc32c9d672affce9a75a6d0a36b7394a13f289449432e2b
MD5 71072ec0604657e0c17eb5c2f6d86839
BLAKE2b-256 9caa21e879947e85753a79079c4face9614b97673b7356d0a46da4a4079065bd

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page