Automatischer Index komplizierter Formeln mit Catcode

Automatischer Index komplizierter Formeln mit Catcode

ursprünglicher Beitrag

Unten sehen Sie den minimal funktionierenden Code für ein Programm, an dem ich gerade arbeite. Mein Problem ist, dass bei Verwendung eines komplizierteren Codes dieser am Ende nicht automatisch indiziert wird.

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

Wenn ich die normale Eingabe mache, um etwas in einen Index einzutragen, wird die komplizierte Formel in einer ähnlichen Form angezeigt. Das ist immer noch nicht ideal. Gibt es eine Möglichkeit, den \catcode besser zu definieren, damit ich kompliziertere Formeln in den Index eingeben kann?

AKTUALISIERTER Code

Nachfolgend sehen Sie den aktualisierten Code basierend auf den Informationen von @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}

Antwort1

Aus den Kommentaren geht hervor, dass @barbara beeton das Problem gefunden hat. Ich poste eine Antwort, damit andere sie finden und lösen können.

  • Syntaxfehler im Originalcode: @ist bereits ein Trennzeichen darin, \makeidxdaher \catcodeverursacht eine Neudefinition Probleme und einen komplexeren Code als nötig.Lösung:Verwenden Sie " als Catcode-Symbol

Danach ließ sich die Datei ohne Fehler kompilieren, im Index würde jedoch noch immer die Formel fehlen.

LÖSUNG

  1. Zunächst müssen Sie verstehen, was in den Protokolldateien der Indizes interpretiert wird. .ilgDie Datei gibt Aufschluss über etwaige Fehler und darüber, ob beim Kompilieren des Index etwas ignoriert wird.Wenn ein Fehler auftritt oder Einträge abgelehnt oder ignoriert werden, fahren Sie mit dem nächsten Schritt fort..
  2. .idxzeigt genau an, was in den Index eingelesen wird. Öffnen Sie dies also in einem beliebigen Textdatei-Reader wie Notepad. Dadurch wird Ihnen angezeigt, wie Ihre Eingabe übersetzt und in den Index eingelesen wird, was Ihnen dabei helfen kann, den problematischen Teil zu lokalisieren. In meinem Fall \sumwurde es als gelesen \DOTSB \sum@ \slimits@.Wenn Ihr Befehl in etwas Ausgefallenes umgewandelt wird, fahren Sie mit dem letzten Schritt fort
  3. \protectverhindert, dass der Befehl in etwas anderes umgewandelt wird. In diesem Fall ist also '$\sum\frac$ jetzt '\protect\sum \frac' und die komplexe Formel erscheint nun wie vorgesehen ohne Fehler im Index. Dies kann auch durch einen Blick auf die .idxund -Dateien bestätigt werden..ilg

ENDGÜLTIGER CODE

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

verwandte Informationen