我希望我的文档在超过定义的长度时立即显示警告。我找到了如何打印文档的总字数(假设主文件为main.tex
):
\newcommand{\mytexcount}{%
\immediate\write18{texcount -merge -sum -0 main.tex > main.wcdetail }%
\verbatiminput{main.wcdetail}%
}
...
\mytexcount
此外,我可以根据阈值条件打印警告,如下所示:
\def\mywordthreshold{3000}
\newcommand{\countwarning}{
\ifnum [some number]>\mywordthreshold
\emph{CAUTION: THIS TEXT SEEMS LONGER THAN \mywordthreshold WORDS}
\fi
}
...
\countwarning
但是,我不确定如何将输出放入\mytexcount
条件中,因为它似乎不能被解释为数字。如果有人能提供帮助或有其他建议,我将不胜感激!
我已经创建了一个最小工作示例背页到目前为止我所得到的。这是它的代码:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{verbatim}
\title{Word Count Example}
\newcommand{\mytexcount}{%
\immediate\write18{texcount -merge -sum -0 main.tex > main.wcdetail }%
\verbatiminput{main.wcdetail}%
}
\def\mywordthreshold{3000}
\newcommand{\countwarning}{
\ifnum 3001>\mywordthreshold
\emph{CAUTION: THIS TEXT SEEMS LONGER THAN \mywordthreshold WORDS}
\fi
}
\begin{document}
\maketitle
\section{Ipsum}
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
\section{Word Count}
Number of words is: \mytexcount
Warning should follow this questionmark? \countwarning
\end{document}
答案1
您可以使用 将的输出保存texcount
在宏中catchfile
。
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{catchfile}
\title{Word Count Example}
\newcommand{\countwarning}[1]{%
\CatchFileEdef\wordcount{"|texcount -merge -sum -0 \jobname.tex"}{}%
\ifnum\wordcount>\mywordthreshold\relax
\typeout{^^J*** WARNING ***^^J*** The file has too many words (>\mywordthreshold) ***^^J}%
\else
\typeout{^^J*** GOOD ***^^J*** The file is below the word limit (\mywordthreshold) ***^^J}%
\fi
}
\newcommand\mywordthreshold{200}
\begin{document}
\maketitle
\section{Ipsum}
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy
eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.
At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd
gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem
ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.
At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd
gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem
ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.
At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd
gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
\countwarning
\end{document}
这将打印在终端窗口上
*** GOOD ***
*** The file is below the word limit (200) ***
如果我将阈值设置为 20,我会得到
*** WARNING ***
*** The file has too many words (>20) ***
您可以轻松更改定义以在文档末尾打印一些内容。