\documentclass[fancyhdr,bookmark]{ctexbook}
\setmainfont{DejaVu Sans} % 設定英文字型
\setromanfont{DejaVu Sans} % 字型
\setmonofont{DejaVu Sans Mono}
\usepackage{ifxetex,ifluatex}
\providecommand{\tightlist}{%
\setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
\usepackage{tikz} % Required for drawing custom shapes
\usepackage[yyyymmdd,hhmmss]{datetime}
\ctexset{today=small}
\usepackage{listings}
\newcommand{\passthrough}[1]{\colorbox{lightgray}{#1}}
\ifxetex
\usepackage[setpagesize=false, % page size defined by xetex
unicode=false, % unicode breaks when used with xetex
xetex]{hyperref}
\else
\usepackage[unicode=true]{hyperref}
\fi
\hypersetup{breaklinks=true,
bookmarks=true,
pdfauthor={John Mike},
pdftitle={PanBook使用手册},
colorlinks=true,
urlcolor=blue,
linkcolor=magenta,
pdfborder={0 0 0}}
\urlstyle{same} % don't use monospace font for urls
\usepackage{longtable,booktabs}
\usepackage{graphicx,grffile}
\makeatletter
\def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth\else\Gin@nat@width\fi}
\def\maxheight{\ifdim\Gin@nat@height>\textheight\textheight\else\Gin@nat@height\fi}
\makeatother
\title{PanBook使用手册\\\vspace{0.5em}{\large 用Markdown和Pandoc写作}}
\author{John Mike}
\date{\today}
\usepackage{geometry}
\newcommand{\devicepc}{
\geometry{
top=1in,
inner=1in,
outer=1in,
bottom=1in,
headheight=3ex,
headsep=2ex
}
}
\devicepc
\definecolor{ocre}{RGB}{243,102,25} % Define the orange color used for highlighting throughout the book
\definecolor{lightgray}{rgb}{0.97,0.97,1}
\renewcommand{\passthrough}[1]{\colorbox{lightgray}{#1}}
\newfontfamily\code{Courier New}
\lstset{
basicstyle=\small\linespread{1}\code,
keywordstyle=\color[rgb]{0.13,0.29,0.53}\textbf,
commentstyle=\color{gray},
identifierstyle=\color[rgb]{0.00,0.00,0.00},
stringstyle=\color[rgb]{0.31,0.60,0.02},
rulesepcolor=\color{red!20!green!20!blue!20},
backgroundcolor=\color[rgb]{0.97,0.97,0.97},
tabsize=4,
breaklines=tr,
showstringspaces=false,
}
\renewcommand{\lstlistingname}{代码}
\usepackage{keyval}
\newlength\Colsep
\setlength\Colsep{10pt}
\usepackage{fancyhdr}
\pagestyle{fancy}
\begin{document}
\frontmatter
\setkeys{Gin}{width=\maxwidth,height=\maxheight,keepaspectratio}
\mainmatter
% 在此命令之后的页码为阿拉伯数字
% 以下为正文
\hypertarget{panbookux624bux518c}{%
\chapter{PanBook手册}\label{panbookux624bux518c}}
\passthrough{\lstinline!PanBook!}是基于\passthrough{\lstinline!Pandoc!}和\passthrough{\lstinline!LaTeX!}开发的一个工具,提供了一些开箱即用的书籍,论文,幻灯片及简历模板,以及一些\passthrough{\lstinline!lua filter!}扩展。用来更方便的使用\passthrough{\lstinline!Pandoc!}将\passthrough{\lstinline!Markdown!}转换为\passthrough{\lstinline!PDF!}或\passthrough{\lstinline!epub!}格式。
\hypertarget{ux5febux901fux5f00ux59cb}{%
\section{快速开始}\label{ux5febux901fux5f00ux59cb}}
以\passthrough{\lstinline!Windows 10!}为例,演示如何使用。
\hypertarget{ux5b89ux88c5ux4f9dux8d56ux8f6fux4ef6}{%
\subsection{安装依赖软件}\label{ux5b89ux88c5ux4f9dux8d56ux8f6fux4ef6}}
\begin{itemize}
\tightlist
\item
安装\href{https://www.msys2.org/}{msys2}
(\passthrough{\lstinline!Linux!}及\passthrough{\lstinline!OS X!}请忽略此步骤)
\item
安装\href{http://mirror.ctan.org/systems/texlive/Images/}{texlive}
2018或以上版本
\item
安装\href{https://pandoc.org/installing.html}{Pandoc} 2.7.1或以上版本
\item
下载\href{https://github.com/lierdakil/pandoc-crossref/releases}{pandoc-crossref}
对应版本安装到\passthrough{\lstinline!path!}目录下(建议和\passthrough{\lstinline!Pandoc!}放同一目录)
\end{itemize}
\hypertarget{ux5b89ux88c5panbook}{%
\subsubsection{安装PanBook}\label{ux5b89ux88c5panbook}}
\passthrough{\lstinline!PanBook!}是一组\passthrough{\lstinline!Shell!}脚本,直接下载到任意目录即可。打开终端(\passthrough{\lstinline!msys2!}),假设工作目录为\passthrough{\lstinline!/d/!},执行代码~\ref{lst:gitclone}。
\begin{lstlisting}[language=bash, caption=安装PanBook, label=lst:gitclone, float=htbp]
$ cd /d/
$ git clone https://github.com/annProg/PanBook
\end{lstlisting}
\hypertarget{ux8bbeux7f6eux73afux5883ux53d8ux91cf}{%
\subsubsection{设置环境变量}\label{ux8bbeux7f6eux73afux5883ux53d8ux91cf}}
需要将本项目,\passthrough{\lstinline!texlive!}及\passthrough{\lstinline!Pandoc!}加入环境变量,如代码~\ref{lst:setpath}所示。
\begin{lstlisting}[language=bash, caption=设置环境变量, label=lst:setpath, float=htbp]
$ tail -n 1 ~/.bashrc
export PATH=$PATH:/d/texlive/2018/bin/win32:/d/dev/PanBook:/c/Users/myname/AppData/Local/Pandoc
\end{lstlisting}
\hypertarget{ux5f00ux59cbux4f7fux7528}{%
\subsection{开始使用}\label{ux5f00ux59cbux4f7fux7528}}
在任意空目录下执行\passthrough{\lstinline!panbook <command>!},会自动初始化写作环境,生成示例源码。然后在\passthrough{\lstinline!src!}目录下开始写作。\passthrough{\lstinline!<command>!}可以是\passthrough{\lstinline!book!},\passthrough{\lstinline!thesis!},\passthrough{\lstinline!slide!},\passthrough{\lstinline!cv!}。详细帮助信息执行\passthrough{\lstinline!panbook -h!}查看。目录规范见代码~\ref{lst:panbookdirs}。
\begin{lstlisting}[language=bash, caption=目录规范, label=lst:panbookdirs, float=htbp]
.
├── templates # 自定义模板
├── styles # 自定义风格
├── extensions # 自定义扩展
├── fonts # 自定义字体
├── build # 电子书构建目录
├── src # Markdown源码目录
│ └── images # 源码涉及插图目录
│ └── metadata.yaml # 书籍元数据文件
│ └── frontmatter.md # 前言文件
│ └── backmatter.md # 后记文件
│ └── 100-chapter1.md # 正文,命名须保证能按正确章节顺序列出
│ └── 200-chapter2.md
\end{lstlisting}
\hypertarget{sec:note}{%
\subsubsection{注意事项}\label{sec:note}}
\begin{itemize}
\tightlist
\item
Markdown源码文件需要使用\passthrough{\lstinline!UTF-8!}编码
\item
Pandoc扩展的Markdown语法要求在标题前留出一个空行,因此按章节拆分的多个Markdown文件,开头需要空一行,否则pandoc不能正确识别标题
\item
请勿将正文文件命名为
\passthrough{\lstinline!*frontmatter.md!}或者\passthrough{\lstinline!*backmatter.md!},这2个文件有特殊用途
\end{itemize}
\hypertarget{ux4e66ux7c4dux5143ux6570ux636e}{%
\section{书籍元数据}\label{ux4e66ux7c4dux5143ux6570ux636e}}
在\passthrough{\lstinline!src/metadata.yaml!}中使用\href{http://www.ruanyifeng.com/blog/2016/07/yaml.html}{Yaml语言}
定义书籍的数据及可用的模板变量,示例见代码~\ref{lst:metayaml}。
\begin{lstlisting}[caption=Metadata, label=lst:metayaml, float=htbp]
---
title: PanBook使用手册
subtitle: 用Pandoc和Markdown写作
author: # 作者(数组)
- John Mike
homepage: https://github.com/annProg/PanBook
header-includes:
- \usepackage{cleveref}
- \usepackage{float}
...
\end{lstlisting}
查看模板文件,可以获取模板支持的所有变量(形如\passthrough{\lstinline!$var$!})。也可以通过修改模板来添加自定义的变量。
\hypertarget{ux5199ux4f5cux5de5ux5177}{%
\section{写作工具}\label{ux5199ux4f5cux5de5ux5177}}
推荐使用 \href{https://code.visualstudio.com/}{Visual Studio
Code}。一些有用的插件见表~\ref{tbl:vscodeplugin}。
\hypertarget{tbl:vscodeplugin}{}
\begin{longtable}[]{@{}lc@{}}
\caption{\label{tbl:vscodeplugin}推荐插件}\tabularnewline
\toprule
插件 & 功能\tabularnewline
\midrule
\endfirsthead
\toprule
插件 & 功能\tabularnewline
\midrule
\endhead
Markdown Preview & Markdown实时预览\tabularnewline
\LaTeX~language support & \LaTeX 语言高亮\tabularnewline
All Autocomplete & 自动补全(支持单词补全)\tabularnewline
\bottomrule
\end{longtable}
使用代码~\ref{lst:vscodeMsys}
将终端改为\passthrough{\lstinline!msys2!}的\passthrough{\lstinline!bash!}。
\begin{lstlisting}[caption={VS Code使用msys2}, label=lst:vscodeMsys, float=htbp]
{
"terminal.integrated.shell.windows": "D:\\msys64\\usr\\bin\\bash.exe",
"terminal.integrated.shellArgs.windows": ["-l"],
"terminal.integrated.env.windows": {
"CHERE_INVOKING": "1",
"MSYSTEM": "MINGW64",
},
"git.postCommitCommand": "push",
"git.path": "D:\\msys64\\git-vscode.bat",
"editor.insertSpaces": false,
"editor.detectIndentation": false,
}
\end{lstlisting}
%\begin{help}
通过 VS Code
Tasks,使用\passthrough{\lstinline!PanBook!}部分编译参数\passthrough{\lstinline!--part=md文件名!},可用快捷键(ctrl+shift+b)编译当前Markdown源文件。
通过 VS Code
Tasks,使用\passthrough{\lstinline!PanBook!}部分编译参数\passthrough{\lstinline!--part=md文件名!},可用快捷键(ctrl+shift+b)编译当前Markdown源文件。
通过 VS Code
Tasks,使用\passthrough{\lstinline!PanBook!}部分编译参数\passthrough{\lstinline!--part=md文件名!},可用快捷键(ctrl+shift+b)编译当前Markdown源文件。
通过 VS Code
Tasks,使用\passthrough{\lstinline!PanBook!}部分编译参数\passthrough{\lstinline!--part=md文件名!},可用快捷键(ctrl+shift+b)编译当前Markdown源文件。
通过 VS Code
Tasks,使用\passthrough{\lstinline!PanBook!}部分编译参数\passthrough{\lstinline!--part=md文件名!},可用快捷键(ctrl+shift+b)编译当前Markdown源文件。
通过 VS Code
Tasks,使用\passthrough{\lstinline!PanBook!}部分编译参数\passthrough{\lstinline!--part=md文件名!},可用快捷键(ctrl+shift+b)编译当前Markdown源文件。
通过 VS Code
Tasks,使用\passthrough{\lstinline!PanBook!}部分编译参数\passthrough{\lstinline!--part=md文件名!},可用快捷键(ctrl+shift+b)编译当前Markdown源文件。
通过 VS Code
Tasks,使用\passthrough{\lstinline!PanBook!}部分编译参数\passthrough{\lstinline!--part=md文件名!},可用快捷键(ctrl+shift+b)编译当前Markdown源文件。
通过 VS Code
Tasks,使用\passthrough{\lstinline!PanBook!}部分编译参数\passthrough{\lstinline!--part=md文件名!},可用快捷键(ctrl+shift+b)编译当前Markdown源文件。
通过 VS Code
Tasks,使用\passthrough{\lstinline!PanBook!}部分编译参数\passthrough{\lstinline!--part=md文件名!},可用快捷键(ctrl+shift+b)编译当前Markdown源文件。
%\end{help}
\backmatter
\end{document}