這是為了指示 LaTeX 文件的更改。比如說,我想在出現“word 1”、“word 2”、...”或“word 100”時在行首添加一條垂直線。可以手動完成此操作,以確定“word”的位置1”出現了,但是如果有很多“單字”並且需要再次重複該過程,那麼這可能會很乏味。
I use this as an example to add vertical line
| when word 1 appears and another vertical line
| word 2 appears.
答案1
我使用我的包的改編版本titlecaps
,通常用於在給定單字字串的情況下將每個單字的第一個字母大寫(用戶指定的例外)。因此,我不會限製字詞,而是保持不變。但是,我使用搜尋使用者指定的異常的程式碼來在左邊距中放置規則並更改突出顯示的單字的顏色(這兩個功能獨立運行,並且可以停用其中一個而不影響另一個)。
我使用該tabto
包來方便邊緣線符號。
\WordsToNote{word1 word2 word3}
要搜尋的單字由巨集(一個空格分隔的清單)指定。後續調用是累積的,因此\WordsToNote{word1 word2}\WordsToNote{word3}
在功能上與前一次調用相同。可以使用 重置單字列表\Resetlcwords
。
該段落的巨集調用很簡單\NoteWords{<text>}
。
與該titlecaps
套件一樣,它可以處理巨集呼叫的有限子集,包括文字大小變更和樣式變更。
編輯一次處理多個段落。已修復,以便\par
在巨集末尾不會自動發出新的。
\documentclass{article}
\usepackage{titlecaps}
\makeatletter
\renewcommand\titlecap[2][P]{%
\digest@sizes%
\if T\converttilde\def~{ }\fi%
\redefine@tertius%
\get@argsC{#2}%
\seek@lcwords{#1}%
\if P#1%
\redefine@primus%
\get@argsC{#2}%
\protected@edef\primus@argi{\argi}%
\else%
\fi%
\setcounter{word@count}{0}%
\redefine@secundus%
\def\@thestring{}%
\get@argsC{#2}%
\if P#1\protected@edef\argi{\primus@argi}\fi%
\whiledo{\value{word@count} < \narg}{%
\addtocounter{word@count}{1}%
\if F\csname found@word\roman{word@count}\endcsname%
\notitle@word{\csname arg\roman{word@count}\endcsname}%
\expandafter\protected@edef\csname%
arg\roman{word@count}\endcsname{\@thestring}%
\else
\notitle@word{\csname arg\roman{word@count}\endcsname}%
\expandafter\protected@edef\csname%
arg\roman{word@count}\endcsname{%
\protect\MPAR\color{red}\@thestring\color{black}{}}%
\fi%
}%
\def\@thestring{}%
\setcounter{word@count}{0}%
\whiledo{\value{word@count} < \narg}{%
\addtocounter{word@count}{1}%
\ifthenelse{\value{word@count} = 1}%
{}{\add@space}%
\protected@edef\@thestring{\@thestring%
\csname arg\roman{word@count}\endcsname}%
}%
\let~\SaveHardspace%
\@thestring%
\restore@sizes%
\un@define}
\makeatother
\usepackage{tabto,xcolor}
\def\margrule{\protect\rule[-\dp\strutbox]{1pt}{\baselineskip}}
\def\MPAR{\protect\tabto*{-.2cm}%
\margrule\protect\tabto*{\TabPrevPos}}
\let\WordsToNote\Addlcwords
\newcommand\NoteWords[1]{\NoteWordsHelp#1\par\relax}
\long\def\NoteWordsHelp#1\par#2\relax{%
\titlecap{#1}%
\ifx\relax#2\else\par\NoteWordsHelp#2\relax\fi%
}
\textwidth4in\relax\sloppy
\begin{document}
\WordsToNote{word1 word2 word3}
\NoteWords{
This is a test of finding word1 and others like word2 and to see if
a marking can be placed in the \textit{margin when they} are found.
I also include word3 in the list. \"Unfortunately, this only does
a single paragraph at a time. \tiny Multiple ocurrences in a
single row only result in a single\normalsize mark, with this word1 implementation.
For my second paragraph,
this is a test of finding word1 and others like word2 and to see if
a marking can be placed in the \textit{margin when they} are found.
I also include word3 in the list. \"Unfortunately, this only does
a single paragraph at a time. \tiny Multiple ocurrences in a
single row only result in a single\normalsize mark, with this word1 implementation.
}
Look Mom, no new paragraph.
\end{document}
請注意:我特意放置在 MWE 程式碼中的行\textwidth4in\relax\sloppy
是為了減少邊距並消除過滿的框框。在其他場所使用此程式碼之前,請先將其刪除。