diff --git a/Makefile b/Makefile index 014638b..8e86f29 100644 --- a/Makefile +++ b/Makefile @@ -1,12 +1,17 @@ -# `make citebib`: Extract all bibliographies cited as BibLaTeX -# `make` or `make all`: Render DOCX, HTML, PDF and Reveal.js slides at once -# `make print`: Render PDF for print -# `make watermark`: Render PDF with watermark -# `make clean`: Remove auxiliary and output files +# `make` or `make all`: Render DOCX, HTML, PDF, ePub and Reveal.js slides at once. +# `make docx`: Render DOCX. +# `make html`: Render HTML. +# `make pdf`: Render PDF. +# `make epub`: Render ePub. +# `make slides`: Render Reveal.js slides. +# `make print`: Render PDF for print. +# `make watermark`: Render PDF with watermark. +# `make citebib`: Extract all bibliographies cited as BibLaTeX file `citebib.bib`. +# `make clean`: Remove auxiliary and output files. -# Render DOCX, HTML, PDF and Reveal.js slides +# Render DOCX, HTML, PDF, ePub and Reveal.js slides at once .PHONY: all -all: docx html pdf slides +all: docx html pdf epub slides # Pandoc command for extracting bibliographies CITE := @pandoc \ @@ -49,7 +54,7 @@ PDF_OUTPUT := index.pdf # Special handling for print PDF .PHONY: print -print: PDF_OPTION := -V draft -M biblatexoptions="backend=biber,backref=false,dashed=false,\ +print: PDF_OPTION := -V draft -M biblatexoptions="backend=biber,backref=false,dashed=false, \ gblabelref=false,gblanorder=englishahead,gbnamefmt=lowercase,gbfieldtype=true,doi=false" print: PDF_OUTPUT := print.pdf print: pdf @@ -60,6 +65,11 @@ watermark: PDF_OPTION := -V watermark=true watermark: PDF_OUTPUT := watermark.pdf watermark: pdf +# Render ePub +epub: dependencies + $(QUARTO) $@ -L _extensions/localize-cnbib.lua -L _extensions/bib-quotes.lua \ + --filter _extensions/sort-cnbib.py --filter _extensions/auto-correct.py + # Render Reveal.js slides slides: dependencies @quarto render slides.qmd --to revealjs --filter _extensions/auto-correct.py diff --git a/README.md b/README.md index 3fba766..9517e0a 100644 --- a/README.md +++ b/README.md @@ -4,14 +4,15 @@ This repository provides a comprehensive guide and toolset for writing academic papers in Chinese, such as the localization and sorting of Chinese -bibliographies, conversion of quotes, and adding space between Chinese and -English Characters. With the help of these templates and scripts, you can write -your academic papers in Markdown, and convert them into various formats like -Word, HTML, LaTeX, PDF, and EPUB via Quarto. +bibliographies, conversion of Chinese quotes, and correcting spaces between +Chinese and English characters. With the help of these templates and scripts, +you can write your academic papers in Markdown, and convert them into various +formats like Word, HTML, LaTeX, PDF, and ePub via Quarto with ease. ## Prerequisites -- [Quarto](https://quarto.org), with [Pandoc](https://pandoc.org) included, and you can install TinyTeX via `quarto install tinytex --update-path`. +- [Quarto](https://quarto.org), with [Pandoc](https://pandoc.org) included, and + you can install TinyTeX via `quarto install tinytex --update-path`. - Python, and the following packages: - [autocorrect_py](https://github.com/huacnlee/autocorrect/tree/main/autocorrect-py) - [pypinyin](https://github.com/mozillazg/python-pinyin) @@ -25,14 +26,15 @@ Word, HTML, LaTeX, PDF, and EPUB via Quarto. This project uses a Makefile to manage the build process. Here are the available commands: -- `make citebib`: Extract all bibliographies cited as BibLaTeX file `citebib.bib`. +- `make` or `make all`: Render DOCX, HTML, PDF, ePub and Reveal.js slides at once. - `make docx`: Render DOCX. - `make html`: Render HTML. - `make pdf`: Render PDF. +- `make epub`: Render ePub. - `make slides`: Render Reveal.js slides. -- `make` or `make all`: Render DOCX, HTML, PDF and Reveal.js slides at once. - `make print`: Render PDF for print. - `make watermark`: Render PDF with watermark. +- `make citebib`: Extract all bibliographies cited as BibLaTeX file `citebib.bib`. - `make clean`: Remove auxiliary and output files. ## License diff --git a/_extensions/bib-quotes.lua b/_extensions/bib-quotes.lua index 5dcd0fd..147d9bc 100644 --- a/_extensions/bib-quotes.lua +++ b/_extensions/bib-quotes.lua @@ -1,4 +1,4 @@ --- Process quotes for Chinese bibliographies in docx and html output +-- Process quotes for Chinese bibliographies in docx, html and epub outputs --- Copyright: © 2024 Tom Ben --- License: MIT License @@ -20,7 +20,7 @@ function quotes_in_bib(block) string.format( '%s', el.text)) - elseif FORMAT:match 'html' then + elseif FORMAT:match 'html' or FORMAT:match 'epub' then local replaced_text = el.text if el.text == "“" then replaced_text = "「" diff --git a/_quarto.yml b/_quarto.yml index 356af8f..c23d797 100644 --- a/_quarto.yml +++ b/_quarto.yml @@ -94,6 +94,10 @@ format: # - gbalign=gb7714-2015 # Add numeric label, redundant for author-year style # - autocite=plain # Add bracket squares in citiations for numeric style + epub: + epub-cover-image: figures/cover.png + rights: © 2024 Tom Ben + revealjs: template: _styles/revealjs.html theme: _styles/metropolis.scss diff --git a/_styles/custom.tex b/_styles/custom.tex index 3ffb034..e857a9d 100644 --- a/_styles/custom.tex +++ b/_styles/custom.tex @@ -48,3 +48,13 @@ \newunicodechar{‹}{‘} \newunicodechar{›}{’} +% Avoid overflow of the code block +\usepackage{fvextra} +\DefineVerbatimEnvironment{Highlighting}{Verbatim}{breaklines,commandchars=\\\{\}} +\RecustomVerbatimEnvironment{verbatim}{Verbatim}{ + showspaces = false, + showtabs = false, + breaksymbolleft={}, + breaklines + } + diff --git a/contents/1-introduction.md b/contents/1-introduction.md index d5299d8..b06f178 100644 --- a/contents/1-introduction.md +++ b/contents/1-introduction.md @@ -28,7 +28,7 @@ Word 却并不是最适合学术论文写作的工具。 在 [Pandoc](https://pandoc.org) [@macfarlane2024] 的加持下,Markdown 可以输出多种格式的文档, -例如 Word、HTML、LaTeX、PDF、EPUB 等。 +例如 Word、HTML、LaTeX、PDF、ePub 等。 基于 Pandoc 开发的 [Quarto](https://quarto.org) [@allaire2024], 不仅能够直接在论文中运行 Python、R 等代码, diff --git a/contents/3-sort-cnbib.md b/contents/3-sort-cnbib.md index b3cc91e..d3fae3e 100644 --- a/contents/3-sort-cnbib.md +++ b/contents/3-sort-cnbib.md @@ -13,19 +13,27 @@ 根据拼音对中文文献进行排序,并且对姓氏读音的多音字进行了特殊处理: ```py -# 多音字的姓氏拼音 -surname_map = { - '葛': 'ge3', - '阚': 'kan4', - '任': 'ren2', - '单': 'shan4', - '解': 'xie4', - '燕': 'yan1', - '尉': 'yu4', - '乐': 'yue4', - '曾': 'zeng1', - '查': 'zha1', -} +def special_pinyin(text): + # 多音字的姓氏拼音 + surname_map = { + '葛': 'ge3', + '阚': 'kan4', + '任': 'ren2', + '单': 'shan4', + '解': 'xie4', + '燕': 'yan1', + '尉': 'yu4', + '乐': 'yue4', + '曾': 'zeng1', + '查': 'zha1', + } + + if contains_chinese(text): + name = text.split(",")[0] if "," in text else text + surname = name[0] + return surname_map.get(surname, "".join([i[0] for i in pinyin(name, style=Style.TONE3)])) + else: + return None ``` 对于参考文献中中文和英文文献哪个在前的问题, diff --git a/contents/5-pangu-space.md b/contents/5-pangu-space.md index e8f216c..6dbf1b7 100644 --- a/contents/5-pangu-space.md +++ b/contents/5-pangu-space.md @@ -19,9 +19,9 @@ 通过 `auto-correct.py` filter,可以实现修改 Pandoc AST, 在 Pandoc 转换过程中自动纠正中英文、数字之间的空格问题, -无需在得到目标格式后再进行修改,特别是对于某些格式(如 EPUB)来说, +无需在得到目标格式后再进行修改,特别是对于某些格式(如 ePub)来说, 无法在转换完成后再进行修改,因此这个 filter 的优势就体现出来了。 需要注意的是,LaTeX 和 Word 会自动处理中英文之间的空格, 因此无需使用这个 Python filter,只有在转换为其他格式时才需要使用, -例如 HTML、EPUB 等格式。 +例如 HTML、ePub 等格式。 diff --git a/figures/cover.png b/figures/cover.png new file mode 100644 index 0000000..c84b950 Binary files /dev/null and b/figures/cover.png differ