Автоматическая индексация сложных формул с помощью catcode

Автоматическая индексация сложных формул с помощью catcode

оригинальный пост

Ниже приведен минимально рабочий код для программы, над которой я работаю. Моя проблема в том, что когда я использую более сложный код, он не индексируется автоматически в конце.

\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вызвало проблемы и более сложный код, чем необходимо.Решение:использовать " в качестве символа кода кота

После этого файл скомпилируется без ошибок, однако в индексе все равно будет отсутствовать формула.

РЕШЕНИЕ

  1. Сначала нужно понять, что интерпретируется в файлах журнала индексов. .ilgФайл сообщит вам, есть ли какие-либо ошибки и было ли что-то проигнорировано в процессе компиляции индекса.Если есть какая-либо ошибка или какие-либо записи отклонены или проигнорированы, перейдите к следующему шагу..
  2. .idxпокажет точно, считывается ли в индекс. поэтому откройте это в любом текстовом файл-ридере, например, в Блокноте. Это покажет вам, как ваш ввод преобразуется и считывается в индекс, что может помочь вам точно определить проблемную часть. В моем случае \sumсчитывался как \DOTSB \sum@ \slimits@.Если ваша команда трансформируется во что-то необычное, то переходите к последнему шагу.
  3. \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}

Связанный контент