
元の投稿
以下は、私が取り組んでいるプログラムの最小限の動作コードです。問題は、より複雑なコードを使用した場合、最後に自動的にインデックスが作成されないことです。
\documentclass{article}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{latexsym}
\usepackage{imakeidx} %allows for multiple indexes
\usepackage{xcolor}
\catcode`"=\active
\def"#1" {\textcolor{white}{#1}} %catcode to color words white, as to hide it on the the compile format
\catcode`@=\active
\def@[#1][#2][#3]@ {#2\index[#1]{$\square$ "#3" #2}} %catcode for FORMULAS that are sent to specific indexes as needed, here I use the catcode for "" in order to hide the letter that will allow for the index to be rearranged. so #3 will denote the order of the index, however it will be invisible to the naked eye on white paper so that the formula indexes are easier to read
%making indexes as needed
% \makeindex[name=NICKNAME, title={INDEX_TITLE},columns=1, intoc]
\makeindex[name=PV, title={Present Value},columns=1, intoc]
\usepackage{lipsum} %creating filler text for demonstration/test purposes
\begin{document}
@[PV][$PV$=summation $\frac{C}{(1+r)^n}$][c]@
\index[PV]{$\square PV = \sum \frac{C}{(1+r)^n}$}
@[PV][$PV = \sum \frac{C}{(1+r)^n}$][b]@
\indexprologue{Present Value is the discounted value, is the value of an expected income stream determined as of the date of valuation}
\printindex[PV]
\end{document}
インデックスに何かを追加するために通常の入力を行うと、複雑な数式が似たような形式で表示されます。これはまだ理想的ではありません。\catcode をより適切に定義して、より複雑な数式をインデックスに入力できるようにする方法はありますか?
更新されたコード
以下は@barbara beetonの情報に基づいて更新されたコードです。
\documentclass{article}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{latexsym}
\usepackage{imakeidx} %allows for multiple indexes
%\usepackage{xcolor} no longer needed
%\catcode`"=\active
%\def"#1" {\textcolor{blue}{#1}} no longer need this as redefined the following catcode
\catcode`"=\active %changed symbol as @ is a seperator in makeidx
\def"[#1][#2][#3]" {#2\index[#1]{#3@$\square$ #2}} %catcode for FORMULAS that are sent to specific indexes as needed, #3 is used to take advantage of the fact that indexes are alphabetical to order the formulas in an organized manor. Ultimately this /catcode is used to print the #2 in the main text AND index #2 into the appropriate index, #1.
%making indexes as needed
% \makeindex[name=NICKNAME, title={INDEX_TITLE},columns=1, intoc]
\makeindex[name=PV, title={Present Value},columns=1, intoc]
\usepackage{lipsum} %creating filler text for demonstration/test purposes
\begin{document}
"[PV][$PV$= summation $\frac{C}{(1+r)^n}$][c]" %appears in index and maintext
\lipsum[2]
"[PV][$PV=\frac{C}{(1+r)^n}$][a]" %appears in index and main text
"[PV][$PV=\sum\frac{C}{(1+r)^n}$][b]" %appears in maintext BUT NOT IN INDEX
%this is what i want to appear in the index using the catcode
%\index[PV]{$\square PV=\sum\frac{C}{(1+r)^n}$}
\indexprologue{Present Value is the discounted value, is the value of an expected income stream determined as of the date of valuation}
\printindex[PV]
\end{document}
答え1
コメントから、@barbara beeton が問題を見つけることができました。他の人が見つけて解決できるように回答を投稿します。
- 元のコードに構文エラーがあります: は
@
すでに区切り文字なので\makeidx
、それを再定義すると\catcode
問題が発生し、必要以上に複雑なコードになります。解決:キャットコードシンボルとして「」を使用する
この後、ファイルはエラーなしでコンパイルされますが、インデックスにはまだ数式が欠落したままになります。
解決
- まず、インデックス ログ ファイルで何が解釈されているかを理解します。
.ilg
ファイルには、エラーがあるかどうか、インデックスのコンパイル プロセスで無視されているものがあるかどうかが示されます。エラーがあったり、エントリが拒否または無視された場合は、次のステップに進みます。。 .idx
は、インデックスに読み込まれている内容を正確に表示します。これをメモ帳などのテキスト ファイル リーダーで開きます。これにより、入力内容がどのように変換され、インデックスに読み込まれているかが表示され、問題のある部分を特定するのに役立ちます。私の場合は、\sum
として読み込まれていました\DOTSB \sum@ \slimits@
。コマンドが何か変なものに変換されてしまったら、最後のステップに進みます\protect
コマンドが別のものに変換されるのを防ぎます。この場合、「$\sum\frac$」は「\protect\sum \frac」になり、複雑な数式がエラーなくインデックスに表示されるようになります。これは、.idx
および.ilg
ファイルを見ても確認できます。
最終コード
\documentclass{article}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{latexsym}
\usepackage{imakeidx} %allows for multiple indexes
\catcode`"=\active
\def"[#1][#2][#3]" {#2\index[#1]{#3@$\square$ #2}} %catcode for FORMULAS that are sent to specific indexes (defined by #1) as needed. #3 is used to take advantage of the fact that indexes are alphabetical to order the formulas in an organized manor. Ultimately this /catcode is used to automatically print the #2 in the main text AND index #2 into the appropriate index at the same time
%making indexes as needed
% \makeindex[name=NICKNAME, title={INDEX_TITLE},columns=1, intoc]
\makeindex[name=PV, title={Present Value},columns=1, intoc]
\begin{document}
%"[PV][$PV=\sum \frac{C}{(1+r)^n}$][b]" %appeared in maintext BUT NOT IN INDEX
"[PV][$PV=\protect\sum \frac{C}{(1+r)^n}$][b]" %appears in both index and main text
\indexprologue{Present Value is the discounted value, is the value of an expected income stream determined as of the date of valuation}
\printindex[PV]
\end{document}