Skip to content

Update PDF rendering #15985

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ gen
/node_modules/

tmp/
doc.md
output.pdf
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
default: output.pdf

doc.md:
./scripts/merge_by_toc.py

output.pdf: doc.md
./scripts/generate_pdf.sh
34 changes: 21 additions & 13 deletions scripts/generate_pdf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
set -e
# test passed in pandoc 1.19.1

# Fedora: dnf install wqy-microhei-fonts
MAINFONT="WenQuanYi Micro Hei"
MONOFONT="WenQuanYi Micro Hei Mono"

Expand All @@ -15,16 +16,23 @@ _version_tag="$(date '+%Y%m%d')"
# default version: `pandoc --latex-engine=xelatex doc.md -s -o output2.pdf`
# used to debug template setting error

pandoc -N --toc --smart --latex-engine=xelatex \
--template=templates/template.tex \
--include-in-header=templates/deeplist.tex \
--columns=80 \
--listings \
-V title="TiDB Documentation" \
-V author="PingCAP Inc." \
-V date="${_version_tag}" \
-V CJKmainfont="${MAINFONT}" \
-V fontsize=12pt \
-V geometry:margin=1in \
-V include-after="\\input{templates/copyright.tex}" \
"doc.md" -s -o "output.pdf"
# Note that doc.md must first be generated by ./scripts/merge_by_toc.py

pandoc \
-s \
-N \
--toc \
-f markdown+smart \
--pdf-engine=xelatex \
--template=templates/template.tex \
--columns=120 \
--listings \
-V title="TiDB Documentation" \
-V author="PingCAP Inc." \
-V date="${_version_tag}" \
-V CJKmainfont="${MAINFONT}" \
-V fontsize=12pt \
-V geometry:margin=1in \
-V include-after="\\input{templates/copyright.tex}" \
-o "output.pdf" \
"doc.md"
1 change: 1 addition & 0 deletions scripts/merge_by_toc.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ def replace_link(match):
or link.endswith(".svg")
or link.endswith(".gif")
or link.endswith(".jpg")
or link.endswith(".PNG")
):
# special handing for pic
img_link = re.sub(r"[\.\/]*media\/", "./media/", link, count=0, flags=0)
Expand Down
5 changes: 4 additions & 1 deletion templates/template.tex
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
\documentclass[$if(fontsize)$$fontsize$,$endif$$if(lang)$$lang$,$endif$$if(papersize)$$papersize$,$endif$$for(classoption)$$classoption$$sep$,$endfor$]{$documentclass$}
\usepackage{array}
\usepackage{calc}
$if(fontfamily)$
\usepackage{$fontfamily$}
$else$
Expand Down Expand Up @@ -67,6 +69,7 @@

\usepackage{xcolor}
\usepackage{listings}
\newcommand{\passthrough}[1]{#1}
\lstset{
basicstyle=\ttfamily,
keywordstyle=\color[rgb]{0.13,0.29,0.53}\bfseries,
Expand Down Expand Up @@ -115,7 +118,7 @@
\hypersetup{breaklinks=true,
bookmarks=true,
pdfauthor={$author-meta$},
pdftitle={$title-meta$},
pdftitle="TiDB User Manual"
colorlinks=true,
citecolor=$if(citecolor)$$citecolor$$else$blue$endif$,
urlcolor=$if(urlcolor)$$urlcolor$$else$blue$endif$,
Expand Down