Why markdown?
Mardown is a lightweight markup language with simple syntax, good readability, and easy conversion into other formats. It is widely used in technical document writing. I believe everyone has a certain understanding of markdown. If you do not know a lot of results on the Internet, you can refer to the markdown syntax description (Simplified Chinese Version ). I am writing documents and ppt files gradually shifting from office to markdown. Its advantage is that
This article briefly introduces how to use markdown to create a slide.
Basic processes and tools
The general process for mardown to create a slide is to first use markdown to write a text file and then convert it to HTML or PDF format using tools. You can modify the CSS or Tex template if necessary. The following tools are used:
- Any text editor: used to edit the markdown source file
- Pandoc: A Tool for converting markdown into other formats (this document mainly introduces PDF)
- Latex: the latex engine is required when pandoc converts markdown to PDF. To support Chinese characters, you can install xelatex
- Beamer: Toolkit for creating slides under Latex
Of course, you can directly use latex + Beamer to create slides, but you need to write the Tex source file, which is more troublesome and less readable than markdown. Therefore, I use markdown to write content and tex as a template.
A basic slide editing markdown source file
Pandoc regards the level 1 title of markdown as a slide group, the level 2 title as a slide title, and the content under the level 2 title as a slide. However, if a level-1 title does not have a level-2 Title, pandoc regards the level-1 title as a slide title, places the content under the level-1 title in a slide, and the level-2 title is displayed as a sub-box.
You can use '---------' to generate a new slide at any time.
Pandoc has an extension for markdown. Add the first three lines with content starting with %, which are the title, author, and date.
Example:
% Title% auther% date# This is a group## This is title 1 This is first slide - item 1 - item 2## This is tile 2 This is second slide------------- This is third slide
Convert to PDF
Save the above Code as exam1.md and run
pandoc -t beamer -o exam1.pdf exam1.md
To generate a PDF file.
Pandoc extension to markdown
Pandoc supports the standard markdown syntax and makes some practical extensions. The title, author, and date above are. In addition, tables and formulas are more practical. For details, see the document of pandoc.
Table
Pandoc supports text-based tables, such
A B C-- -- -- a b c
Or
| A | B | C ||---|---|---|| a | b | c |
Formula
Pandoc supports latex formula syntax. you can insert a formula in the row between $... $. If you want to separate the formula into one row, use two $ s, that is$$ ... $$
.
Chinese support
To display Chinese characters properly, pay attention to the following two points:
- Use xelatex Engine
- Correct configuration in the template file
First, export the default Beamer configuration of pandoc.
pandoc -D beamer > beamer-template.tex
Add Chinese support after \ ifxetex
\ Usepackage {xecjk} % set Chinese and English fonts \ setcjkmainfont {wenquanyi micro Hei} % Chinese fonts \ setmainfont {Arial} % English fonts \ setromanfont {Courier New} \ setmonofont {Courier New }\ linespread {1.2} \ selectfont % line spacing \ xetexlinebreaklocale "ZH" % \ xetexlinebreakskip = 0pt plus 1pt % add 0pt to 1pt spacing \ parindent 0em % segment indent \ setlength {\ parskip} {20pt} % segment spacing
Use commands during compilation
pandoc -t beamer --latex-engine=xelatex --template=beamer-template.tex xx.md -o xx.pdf
Practical Tips: Set the page proportion
Add the parameter aspectratio = 169 to the documentclass of the template file, that is
\documentclass[..., aspectratio=169]{$documentclass$}
You can set the page proportion to (default ).
Set background image
In my work, I need to use the company's PPT template, so I need to set the background of the slides. The final solution is as follows:
Add commands to the template file
\usebackgroundtemplate{\includegraphics[width=\paperwidth, height=\paperheight]{background.png}}
If you want to set a separate background for the title page, I use the method in this article:
\RequirePackage{tikz}\addtobeamertemplate{title page}{% \begin{tikzpicture}[remember picture,overlay] \node [xshift=0cm,yshift=0cm] at (current page.center) {\includegraphics[width=\paperwidth, height=\paperheight]{background_title.png}}; \end{tikzpicture}%}{}
Conclusion
With this, you can use markdown to complete the slide creation task.
Use markdown + pandoc + latex + Beamer to create slides