単語が出現する行の先頭に記号を挿入するにはどうすればよいでしょうか?

単語が出現する行の先頭に記号を挿入するにはどうすればよいでしょうか?

これは、LaTeX ファイルの変更を示すためのものです。たとえば、「単語 1」、「単語 2」、...、または「単語 100」が出現するたびに、行の先頭に縦線を追加したいとします。手動でこれを行うと、「単語 1」が出現する場所を特定できますが、「単語」が多数あり、プロセスを再度繰り返す必要がある場合は面倒です。では、これをインテリジェントに行う方法は何でしょうか。

I use this as an example to add vertical line 
| when word 1 appears and another vertical line
| word 2 appears.

答え1

私はtitlecaps、通常各単語の最初の文字を大文字にするために使用されるパッケージを、単語の文字列 (ユーザー指定の例外あり) に対して適応させて使用します。したがって、単語を大文字にするのではなく、そのままにします。ただし、左余白にルールを配置し、強調表示された単語の色を変更するために、ユーザー指定の例外を検索するコードを使用します (これら 2 つの機能は独立して動作し、一方を無効にしても他方には影響しません)。

私はこの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}

ここに画像の説明を入力してください

注意: この行は、\textwidth4in\relax\sloppy余白を減らしてボックスがいっぱいにならないようにするために、MWE コードに意図的に配置したものです。このコードを他の場所で使用する前に、削除してください。

関連情報