Índice automático de fórmulas complicadas con catcode

Índice automático de fórmulas complicadas con catcode

publicación original

A continuación se muestra el código mínimamente funcional para un programa en el que estoy trabajando. Mi problema es que cuando utilicé código más complicado, no se indexa automáticamente al final.

\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}

Cuando hago la entrada normal para agregar algo a un índice, la fórmula complicada aparece de forma similar. Esto todavía no es lo ideal. ¿Hay alguna manera de definir mejor \catcode para poder ingresar fórmulas más complicadas en el índice?

Código ACTUALIZADO

A continuación se muestra el código actualizado basado en la información de @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}

Respuesta1

Entonces, a partir de los comentarios, @barbara beeton pudo encontrar el problema. Estoy publicando una respuesta para que otros puedan encontrarla y resolverla.

  • Error de sintaxis en el código original: @ya es un separador al \makeidxredefinir de tal manera que \catcodecausa problemas y un código más complejo de lo necesario.Solución:use " como símbolo de código cat

Después de esto, el archivo se compilaría sin errores; sin embargo, aún faltaría una fórmula en el índice.

SOLUCIÓN

  1. Primero, comprenda qué se interpreta en los archivos de registro de índices. .ilgEl archivo le indicará si hay algún error y si se ignora algo en el proceso de compilación del índice.Si hay algún error o si alguna entrada es rechazada o ignorada. Vaya al siguiente paso.
  2. .idxmostrará exactamente lo que se está leyendo en el índice. así que ábralo en cualquier lector de archivos de texto como el Bloc de notas. Esto le mostrará cómo se traduce y lee su entrada en el índice, lo que puede ayudarle a identificar la parte problemática. En mi caso \sumse estaba leyendo como \DOTSB \sum@ \slimits@.Si su comando se está transformando en algo original, continúe con el último paso
  3. \protectevitará que el comando se transforme en otra cosa. Entonces, en este caso, '$\sum\frac$ ahora es '\protect\sum \frac' y ahora la fórmula compleja aparece en el índice como debería, sin ningún error. Esto se puede confirmar mirando los archivos .idxy .ilgtambién.

CÓDIGO FINAL

\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}

información relacionada