【发布时间】:2017-09-20 09:13:59
【问题描述】:
我正在用 Rmarkdown 写一篇论文(通过 LaTeX 导出为 PDF),我需要计算正文中的单词数。对于 LaTeX 文档,我在命令行中使用 texcount,在我的 tex 文档中使用以下标签指定要从字数统计中排除的部分:
%TC:ignore
The part that is to be ignored (e.g., Appendix)
%TC:endignore
如何在我的 Rmd 文件中包含 LaTeX cmets 以避免每次重新生成它时在我的 tex 文件中手动添加 %TC 行?
这是我的 MWE .Rmd:
---
output:
pdf_document:
keep_tex: yes
---
Words that I want to count.
<!-- TC:ignore -->
Words that I want to exclude but cannot,
because the comments do not appear in the `.tex` file.
<!-- TC:endignore -->
%TC:ignore
Other words that I want to exclude but this does not work either
because `%` is not interpreted as \LaTeX comment.
%TC:endignore
#%TC:ignore
Another attempt; it does not work because `#` is for sections,
not comments.
#%TC:endignore
一旦我编织了 .Rmd 文件并输出了 .tex 文件,我会输入:
texcount MWE.tex
答案应该是 6 个字。 谢谢!
更新 1:
在 Twitter 上,@amesoudi 建议使用 RStudio 插件 (WordCountAddIn) 来计算我的 Rmd 文档中的单词。该插件在https://github.com/benmarwick/wordcountaddin 处可用。但是,这不是自动化的,仍然涉及一些指向和单击。
更新 2:
另一种解决方案是
使用特定的表达式来识别什么应该是 LaTeX cmets,例如
LATEXCOMMENT%TC:ignore在.Rmd文件中,有一个脚本可以自动删除生成的
.tex文档中的LATEXCOMMENT表达式(例如sed)
【问题讨论】:
标签: latex knitr r-markdown