1
您可以使用LaTeX读取文件并搜索关键词吗?你会如何做到这一点?乳胶:在文件中搜索关键字
我目前有读取文件和计算行数的代码。我在考虑在每行阅读过程中,我可以解析特定单词或标签的行。这可以做到吗?
\documentclass{book}
\usepackage{ifthen}
\newcounter{FileLines}
\newboolean{RestFile}
\newcommand{\FileLine}{}
\newread\File
\newcommand{\CountLinesInFile}[2]
{
\setboolean{RestFile}{true}
\setcounter{FileLines}{0}
\openin\File=#1
\whiledo{\boolean{RestFile}}
{
\ReadNextLine{\File}
\ifthenelse{\boolean{RestFile}}{
\stepcounter{FileLines}
}{}
}
\closein\File
}
\newcommand{\ReadNextLine}[1]{
\ifthenelse{\boolean{RestFile}}{
\read#1 to \FileLine
\ifeof#1\setboolean{RestFile}{false}
\else % if last line already is read, EOF appears here
\fi
}{}
}
\begin{document}
\CountLinesInFile{textfile.txt}
Lines in file: \arabic{FileLines}
\end{document}
只是一个想法,为什么不只是使用'\ index'来标记关键字? –