January 30, 2024 / by Yu-Shin, Hu
Mathematical formulas and pictures can be converted successfully!
Step 1. Install the latest pandoc
- Pandoc installer
- For Windows system, download pandoc-3.1.11-windows-x86_64.msi
Step 2. Run in cmd: pandoc -s "input_file.format" -o "output_file.format"
- Remember to assign desired filename extension behind the input & output files
- Convert Latex to Word:
pandoc -s "input_file.tex" -o "output_file.docx"
- Convert Latex to Markdown:
pandoc -s "input_file.tex" -o "output_file.md"
- Faster to use the extension on VScode: Markdown PDF
- Rewrite
markdown-pdf.css
toSettings.json
, more details see vscode-markdown-pdf /styles - Here I download
markdown-pdf.css
and rewrite it to mymarkdown-pdf.css
body {
font-family: "Calibri", "Times New Roman", "Arial", "KaiTi", "Microsoft Yahei",
sans-serif;
padding: 0 12px;
}
pre {
background-color: #f8f8f8;
border: 1px solid #cccccc;
border-radius: 3px;
overflow-x: auto;
white-space: pre-wrap;
overflow-wrap: break-word;
}
pre:not(.hljs) {
padding: 23px;
line-height: 19px;
}
blockquote {
background: rgba(127, 127, 127, 0.1);
border-color: rgba(0, 122, 204, 0.5);
}
.emoji {
height: 1.4em;
}
code {
font-size: 12px;
line-height: 19px;
}
/* for inline code */
:not(pre):not(.hljs) > code {
color: rgb(212, 69, 69);
font-size: inherit;
font-family: "Calibri", "Times New Roman", "Arial", "KaiTi", "Microsoft Yahei",
sans-serif;
background-color: #f3f3f3;
padding: 2px 4px;
border-radius: 3px;
}
/* Page Break : use <div class="page"/> to insert page break
-------------------------------------------------------- */
.page {
page-break-after: always;
}
Step 1. Install the latest pandoc
- See the above.
Step 2. Install a LaTeX distribution
- (Not recommended) Download the network install from the official website: TeX Live (it involves downloading and installing required files from the source server, which may take several hours).
- (Recommended) Download the pre-packaged installation image (*.iso) at once:
- Enter 清华大学镜像站 and download
texlive2024.iso
- Open the downloaded ISO file and double-click
install-tl-windows.bat
to install.
- Enter 清华大学镜像站 and download
Step 3. Find a valid Chinese font (if the document has Chinese)
- Run in cmd to see the available Chinese font:
fc-list :lang=zh
The font name follows the font file location. For example,C:/WINDOWS/Fonts/mingliu.ttc: MingLiU,細明體:style=Regular
, font name is called MingLiU. - Or download more fonts: Google Fonts / DaFont
Step 4. Set styling for the output pdf
- Download the
head.tex
into the same folder with yourinput.md
to render document styles.
\usepackage{fancyvrb,newverbs}
\usepackage{hyperref}
\usepackage[top=2cm, bottom=1.5cm, left=2cm, right=2cm]{geometry}
% change background color for inline code
\definecolor{bgcolor}{HTML}{E0E0E0}
\let\oldtexttt\texttt
\renewcommand{\texttt}[1]{
\colorbox{bgcolor}{\oldtexttt{#1}}
}
%% color and other settings for hyperref package
\hypersetup{
bookmarksopen=true,
linkcolor=blue,
filecolor=magenta,
urlcolor=RoyalBlue,
}
- Or download an existing LaTeX template: follow how to set up Latex template
Step 5. Run in cmd: pandoc "input_file.format" -o "input_file.format" --pdf-engine=xelatex -V mainfont='font_name'
- Convert Markdown to PDF using custom styling:
pandoc README.md -o README.pdf --pdf-engine=xelatex -V CJKmainfont='PMingLiU' -V mainfont='Times New Roman' -H head.tex
- Convert Markdown to PDF using an existing template (Eisvogel is used here):
pandoc README.md -o README.pdf --pdf-engine=xelatex -V CJKmainfont='PMingLiU' -V mainfont='Times New Roman' --from markdown --template eisvogel --listings
About TeX Live installation
About rendering styles in TeXLive