Skip to content

Commit

Permalink
deploy: b794988
Browse files Browse the repository at this point in the history
  • Loading branch information
TomBener committed May 28, 2024
1 parent 15726aa commit 327e0e9
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 18 deletions.
Binary file modified index.docx
Binary file not shown.
Binary file added index.epub
Binary file not shown.
44 changes: 26 additions & 18 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ <h1 class="title">用 Quarto 写作中文学术论文</h1>
</div>
</div>
<div class="quarto-title-meta-column-end quarto-other-formats-target">
<div class="quarto-alternate-formats"><div class="quarto-title-meta-heading">其他格式</div><div class="quarto-title-meta-contents"><p><a href="index.docx"><i class="bi bi-file-word"></i>MS Word</a></p></div><div class="quarto-title-meta-contents"><p><a href="index.pdf"><i class="bi bi-file-pdf"></i>PDF</a></p></div><div class="quarto-title-meta-contents"><p><a href="slides.html"><i class="bi bi-file-slides"></i>RevealJS</a></p></div></div></div>
<div class="quarto-alternate-formats"><div class="quarto-title-meta-heading">其他格式</div><div class="quarto-title-meta-contents"><p><a href="index.docx"><i class="bi bi-file-word"></i>MS Word</a></p></div><div class="quarto-title-meta-contents"><p><a href="index.pdf"><i class="bi bi-file-pdf"></i>PDF</a></p></div><div class="quarto-title-meta-contents"><p><a href="index.epub"><i class="bi bi-file"></i>ePub</a></p></div><div class="quarto-title-meta-contents"><p><a href="slides.html"><i class="bi bi-file-slides"></i>RevealJS</a></p></div></div></div>
</div>


Expand Down Expand Up @@ -196,7 +196,7 @@ <h2 id="toc-title">目录</h2>
<section id="前言" class="level2" data-number="1">
<h2 data-number="1" class="anchored" data-anchor-id="前言"><span class="header-section-number">1</span> 前言</h2>
<p>学术论文写作,是科研工作的核心环节。写好一篇学术论文,不仅需要有大量的文献阅读、扎实的实证研究,还需要有清晰的逻辑思维、精准的表达能力。除此之外,「用什么工具写」也是一个非常重要的问题。在绝大多数情况下,学术论文的写作工具是 <a href="https://microsoft.com/en-us/microsoft-365/word">Microsoft Word</a>,无论是学术期刊、学位论文、还是科研项目报告,Word 似乎都是不假思索的首选项。然而,作为一款文字处理软件,Word 却并不是最适合学术论文写作的工具。尤其是在参考文献管理、公式编辑、版本控制等方面。在理工科领域,<a href="https://latex-project.org">LaTeX</a> 是一种非常流行的学术论文写作工具。与 Word 不同,LaTeX 是一种排版系统,而不是所见即所得的文字处理软件,尽管它的排版效果非常出色,但学习曲线也相对陡峭。</p>
<p>在学术论文写作方面,Word 使用体验较差,LaTeX 学习曲线陡峭,这两者似乎都不是完美的选择。有没有一种既易于上手,又能够满足学术论文写作需求的工具呢?答案是肯定的,这个工具就是 <a href="https://daringfireball.net/projects/markdown">Markdown</a>。作为一种轻量级标记语言,Markdown 的语法简单、易读易写。使用 Markdown 写作,不需要关心排版样式,只需要关注写作内容本身,在 <a href="https://pandoc.org">Pandoc</a> <span id="cite_2"><span class="citation" data-cites="macfarlane2024">(<a href="#ref-macfarlane2024" role="doc-biblioref">MacFarlane&nbsp;et al., 2024</a>)</span></span> 的加持下,Markdown 可以输出多种格式的文档,例如 Word、HTML、LaTeX、PDF、EPUB 等。基于 Pandoc 开发的 <a href="https://quarto.org">Quarto</a> <span id="cite_3"><span class="citation" data-cites="allaire2024">(<a href="#ref-allaire2024" role="doc-biblioref">Allaire&nbsp;et al., 2024</a>)</span></span>,不仅能够直接在论文中运行 Python、R 等代码,还增加了很多学术写作的实用功能,例如交叉引用、参考文献预览、可视化编辑等,是学术写作的理想工具 <span id="cite_4"><span class="citation" data-cites="tenen2014">(<a href="#ref-tenen2014" role="doc-biblioref">Tenen&nbsp;et al., 2014</a>)</span></span></p>
<p>在学术论文写作方面,Word 使用体验较差,LaTeX 学习曲线陡峭,这两者似乎都不是完美的选择。有没有一种既易于上手,又能够满足学术论文写作需求的工具呢?答案是肯定的,这个工具就是 <a href="https://daringfireball.net/projects/markdown">Markdown</a>。作为一种轻量级标记语言,Markdown 的语法简单、易读易写。使用 Markdown 写作,不需要关心排版样式,只需要关注写作内容本身,在 <a href="https://pandoc.org">Pandoc</a> <span id="cite_2"><span class="citation" data-cites="macfarlane2024">(<a href="#ref-macfarlane2024" role="doc-biblioref">MacFarlane&nbsp;et al., 2024</a>)</span></span> 的加持下,Markdown 可以输出多种格式的文档,例如 Word、HTML、LaTeX、PDF、ePub 等。基于 Pandoc 开发的 <a href="https://quarto.org">Quarto</a> <span id="cite_3"><span class="citation" data-cites="allaire2024">(<a href="#ref-allaire2024" role="doc-biblioref">Allaire&nbsp;et al., 2024</a>)</span></span>,不仅能够直接在论文中运行 Python、R 等代码,还增加了很多学术写作的实用功能,例如交叉引用、参考文献预览、可视化编辑等,是学术写作的理想工具 <span id="cite_4"><span class="citation" data-cites="tenen2014">(<a href="#ref-tenen2014" role="doc-biblioref">Tenen&nbsp;et al., 2014</a>)</span></span></p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
Expand Down Expand Up @@ -255,19 +255,27 @@ <h3 data-number="2.5" class="anchored" data-anchor-id="tran.和trans.替换为
<h2 data-number="3" class="anchored" data-anchor-id="中文参考文献按照拼音排序"><span class="header-section-number">3</span> 中文参考文献按照拼音排序</h2>
<p>在著者年份制的参考文献表中,中文参考文献一般需要按照拼音排序。基于 GB/T 7714-2015 的 BiLaTeX 样式包 <a href="https://github.com/hushidong/biblatex-gb7714-2015">biblatex-gb7714-2015</a> 支持使用 <code>biber</code> 对中文文献按照排序,但对于 Pandoc 使用的 Citeproc 来说,并不支持这个功能。因此,中文参考文献的排序问题一直是一个头疼的问题。</p>
<p>本项目使用 Python filter <code>sort-cnbib.py</code> 来解决这个问题,借助 Python 的 <code>pypinyin</code> 库获取中文文献的著者拼音,然后通过 Panflute <span id="cite_15"><span class="citation" data-cites="correia2024">(<a href="#ref-correia2024" role="doc-biblioref">Correia, 2024</a>)</span></span> 修改 Pandoc AST,根据拼音对中文文献进行排序,并且对姓氏读音的多音字进行了特殊处理:</p>
<div class="sourceCode" id="cb2"><pre class="sourceCode py code-with-copy"><code class="sourceCode python"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a><span class="co"># 多音字的姓氏拼音</span></span>
<span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a>surname_map <span class="op">=</span> {</span>
<span id="cb2-3"><a href="#cb2-3" aria-hidden="true" tabindex="-1"></a> <span class="st">'葛'</span>: <span class="st">'ge3'</span>,</span>
<span id="cb2-4"><a href="#cb2-4" aria-hidden="true" tabindex="-1"></a> <span class="st">'阚'</span>: <span class="st">'kan4'</span>,</span>
<span id="cb2-5"><a href="#cb2-5" aria-hidden="true" tabindex="-1"></a> <span class="st">'任'</span>: <span class="st">'ren2'</span>,</span>
<span id="cb2-6"><a href="#cb2-6" aria-hidden="true" tabindex="-1"></a> <span class="st">'单'</span>: <span class="st">'shan4'</span>,</span>
<span id="cb2-7"><a href="#cb2-7" aria-hidden="true" tabindex="-1"></a> <span class="st">'解'</span>: <span class="st">'xie4'</span>,</span>
<span id="cb2-8"><a href="#cb2-8" aria-hidden="true" tabindex="-1"></a> <span class="st">'燕'</span>: <span class="st">'yan1'</span>,</span>
<span id="cb2-9"><a href="#cb2-9" aria-hidden="true" tabindex="-1"></a> <span class="st">'尉'</span>: <span class="st">'yu4'</span>,</span>
<span id="cb2-10"><a href="#cb2-10" aria-hidden="true" tabindex="-1"></a> <span class="st">'乐'</span>: <span class="st">'yue4'</span>,</span>
<span id="cb2-11"><a href="#cb2-11" aria-hidden="true" tabindex="-1"></a> <span class="st">'曾'</span>: <span class="st">'zeng1'</span>,</span>
<span id="cb2-12"><a href="#cb2-12" aria-hidden="true" tabindex="-1"></a> <span class="st">'查'</span>: <span class="st">'zha1'</span>,</span>
<span id="cb2-13"><a href="#cb2-13" aria-hidden="true" tabindex="-1"></a>}</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="sourceCode" id="cb2"><pre class="sourceCode py code-with-copy"><code class="sourceCode python"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a><span class="kw">def</span> special_pinyin(text):</span>
<span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a> <span class="co"># 多音字的姓氏拼音</span></span>
<span id="cb2-3"><a href="#cb2-3" aria-hidden="true" tabindex="-1"></a> surname_map <span class="op">=</span> {</span>
<span id="cb2-4"><a href="#cb2-4" aria-hidden="true" tabindex="-1"></a> <span class="st">'葛'</span>: <span class="st">'ge3'</span>,</span>
<span id="cb2-5"><a href="#cb2-5" aria-hidden="true" tabindex="-1"></a> <span class="st">'阚'</span>: <span class="st">'kan4'</span>,</span>
<span id="cb2-6"><a href="#cb2-6" aria-hidden="true" tabindex="-1"></a> <span class="st">'任'</span>: <span class="st">'ren2'</span>,</span>
<span id="cb2-7"><a href="#cb2-7" aria-hidden="true" tabindex="-1"></a> <span class="st">'单'</span>: <span class="st">'shan4'</span>,</span>
<span id="cb2-8"><a href="#cb2-8" aria-hidden="true" tabindex="-1"></a> <span class="st">'解'</span>: <span class="st">'xie4'</span>,</span>
<span id="cb2-9"><a href="#cb2-9" aria-hidden="true" tabindex="-1"></a> <span class="st">'燕'</span>: <span class="st">'yan1'</span>,</span>
<span id="cb2-10"><a href="#cb2-10" aria-hidden="true" tabindex="-1"></a> <span class="st">'尉'</span>: <span class="st">'yu4'</span>,</span>
<span id="cb2-11"><a href="#cb2-11" aria-hidden="true" tabindex="-1"></a> <span class="st">'乐'</span>: <span class="st">'yue4'</span>,</span>
<span id="cb2-12"><a href="#cb2-12" aria-hidden="true" tabindex="-1"></a> <span class="st">'曾'</span>: <span class="st">'zeng1'</span>,</span>
<span id="cb2-13"><a href="#cb2-13" aria-hidden="true" tabindex="-1"></a> <span class="st">'查'</span>: <span class="st">'zha1'</span>,</span>
<span id="cb2-14"><a href="#cb2-14" aria-hidden="true" tabindex="-1"></a> }</span>
<span id="cb2-15"><a href="#cb2-15" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb2-16"><a href="#cb2-16" aria-hidden="true" tabindex="-1"></a> <span class="cf">if</span> contains_chinese(text):</span>
<span id="cb2-17"><a href="#cb2-17" aria-hidden="true" tabindex="-1"></a> name <span class="op">=</span> text.split(<span class="st">","</span>)[<span class="dv">0</span>] <span class="cf">if</span> <span class="st">","</span> <span class="kw">in</span> text <span class="cf">else</span> text</span>
<span id="cb2-18"><a href="#cb2-18" aria-hidden="true" tabindex="-1"></a> surname <span class="op">=</span> name[<span class="dv">0</span>]</span>
<span id="cb2-19"><a href="#cb2-19" aria-hidden="true" tabindex="-1"></a> <span class="cf">return</span> surname_map.get(surname, <span class="st">""</span>.join([i[<span class="dv">0</span>] <span class="cf">for</span> i <span class="kw">in</span> pinyin(name, style<span class="op">=</span>Style.TONE3)]))</span>
<span id="cb2-20"><a href="#cb2-20" aria-hidden="true" tabindex="-1"></a> <span class="cf">else</span>:</span>
<span id="cb2-21"><a href="#cb2-21" aria-hidden="true" tabindex="-1"></a> <span class="cf">return</span> <span class="va">None</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<p>对于参考文献中中文和英文文献哪个在前的问题,各个学校和期刊的要求不一样,有的要求中文在前,有的要求非中文(英文)在前。<code>sort-cnbib.py</code> 默认是英文在前,如果你需要在中文在前,可以将对应代码修改为:</p>
<div class="sourceCode" id="cb3"><pre class="sourceCode py code-with-copy"><code class="sourceCode python"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a><span class="cf">for</span> elem <span class="kw">in</span> doc.content:</span>
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a> <span class="cf">if</span> <span class="bu">isinstance</span>(elem, pf.Div) <span class="kw">and</span> <span class="st">"references"</span> <span class="kw">in</span> elem.classes:</span>
Expand Down Expand Up @@ -295,8 +303,8 @@ <h2 data-number="5" class="anchored" data-anchor-id="中西文盘古之白"><spa
</blockquote>
<p>尽管手动在中英文、数字之间加一个空格是一个好 <a href="https://www.zhihu.com/question/19587406">习惯</a>,然而在实际写作中,我们往往会忘记这个细节,因此在排版时,我们可以借助工具来自动完成这个工作。</p>
<p>本项目提供了一个 Python filter <code>auto-correct.py</code> 来解决这个问题,借助 <a href="https://github.com/huacnlee/autocorrect">AutoCorrect</a> <span id="cite_16"><span class="citation" data-cites="lee2024c">(<a href="#ref-lee2024c" role="doc-biblioref">Lee, 2024</a>)</span></span> 的 Python 库,「自动纠正」或「检查并建议」文案,给 CJK(中文、日语、韩语)与英文混写的场景,补充正确的空格,纠正单词,同时尝试以安全的方式自动纠正标点符号等。</p>
<p>通过 <code>auto-correct.py</code> filter,可以实现修改 Pandoc AST,在 Pandoc 转换过程中自动纠正中英文、数字之间的空格问题,无需在得到目标格式后再进行修改,特别是对于某些格式(如 EPUB)来说,无法在转换完成后再进行修改,因此这个 filter 的优势就体现出来了。</p>
<p>需要注意的是,LaTeX 和 Word 会自动处理中英文之间的空格,因此无需使用这个 Python filter,只有在转换为其他格式时才需要使用,例如 HTML、EPUB 等格式。</p>
<p>通过 <code>auto-correct.py</code> filter,可以实现修改 Pandoc AST,在 Pandoc 转换过程中自动纠正中英文、数字之间的空格问题,无需在得到目标格式后再进行修改,特别是对于某些格式(如 ePub)来说,无法在转换完成后再进行修改,因此这个 filter 的优势就体现出来了。</p>
<p>需要注意的是,LaTeX 和 Word 会自动处理中英文之间的空格,因此无需使用这个 Python filter,只有在转换为其他格式时才需要使用,例如 HTML、ePub 等格式。</p>
</section>
<section id="bibliography" class="level2 unnumbered">

Expand Down Expand Up @@ -1097,7 +1105,7 @@ <h2 data-number="5" class="anchored" data-anchor-id="中西文盘古之白"><spa
});
</script>
</div> <!-- /content -->
<script>var lightboxQuarto = GLightbox({"descPosition":"bottom","selector":".lightbox","closeEffect":"zoom","loop":false,"openEffect":"zoom"});
<script>var lightboxQuarto = GLightbox({"closeEffect":"zoom","selector":".lightbox","loop":false,"descPosition":"bottom","openEffect":"zoom"});
(function() {
let previousOnload = window.onload;
window.onload = () => {
Expand Down
Binary file modified index.pdf
Binary file not shown.
Binary file added index_files/figure-epub/unnamed-chunk-1-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified index_files/figure-pdf/unnamed-chunk-1-1.pdf
Binary file not shown.

0 comments on commit 327e0e9

Please sign in to comment.