This is a request for feedback that may surprise those that have read my many messages about using Scrivener with LaTeX. For all the flexibility and capability that Scrivener+LaTeX offers, I have run into a full-stop roadblock that is apparently intrinsic to LaTeX, NOT Scrivener.
For all the flexibility and power that comes with Scrivener+LaTeX, there is a ‘feature’ of LaTeX for which I now believe there is NO workaround. The ‘feature’ in question is how LaTeX treats \index items that include macros. The issue was outlined in a 15 January 1998 document “Tips on Indexing LATEX Documents” by Nelson H. F. Beebe available at https://www.math.utah.edu/~beebe/talks/1998/idxtips.pdf.
As mentioned earlier, the argument of \index is treated to little more than a brace balance check, and written out directly to the .idx file. In particular, any TEX macros present will NOT be expanded. This is convenient, because those macros will be expanded when the .ind file is later read, and their premature expansion would clutter the .idx file and possibly interfere with sorting. (Emphasis added)
This LaTeX ‘feature’ effectively suspends the expansion of all macros within the LaTeX \indexes until the end of the compiling process when the \index is ultimately compiled.
I wanted to build a LaTeX \index that employs a macro that includes a LaTeX ‘Counter’ (similar to Scrivener’s <$n> placeholder but much more powerful) as a way to incrementally follow my use of ‘bounding boxes’ available from the tcolorbox package that uses TikZ. (that’s a mouthful!)
As I learned (and outlined above), a fundamental feature of LaTeX, is that a LaTeX \index does NOT, repeat, NOT, expand ANY macro included in a call to \index, until the end of the compiling process when the \index is ultimately compiled. Full STOP.
The following ‘BBoxIndex’ macro includes a call to the \theBBoxnum macro that represents the ‘Counter’ BBoxnum that is incremented by 1 with each sequential ‘bounding box’ I have in my Scrivener project. The \Lemmatext macro includes a title caption that is unique for each ‘bounding box’.
\newcommand{\BBoxIndex}[2]{\index{Lemma!{\theBBoxnum{\Lemmatext}}}}
The following is the second of what I had hoped would be one of many ‘bounding boxes’ in my project, each with a separate reference in my project index.
My idea was to include the title caption “Lemma # 2: Thermal heat energy” that appears at the top of the above ‘bounding box’ in the index with the appropriate hyperlinked page number. Instead what appears in the index is:
At the moment, I have 10 ‘bounding boxes’ in my project. The caption at the top of the last (10’th) ‘bounding box’: “# 10: Lies, anti-science, and climate denial” is the only one (of the 10) that appears in the index. This happens as the LaTeX ‘feature’ suspends macro \index expansions until the \index is compiled resulting in the macro expansion of whatever is the last title caption for the ‘bounding boxes’. This results in the macro expansion for the last ‘bounding box’ as #10: …
If the LaTeX macros were expanded dynamically during compilation, there would be 10 ‘bounding boxes’ (#1, #2, #3, … #10 ) with their title captions listed in the project index.
I’ve hit a wall and cannot see a way around the LaTeX \index limitation that prohibits the dynamic expansion of the unique BBoxnum and \Lemmatext macros for each ‘bounding box’.
Please note that, given the context of the Scrivener application as it currently stands, I am calling this out as a LaTeX limitation, NOT as a Scrivener limitation (or shortcoming) in any way.
Any feedback, thoughts, comments and/or suggestions appreciated!
Thanks for reading,
scrive
P.S. For those interested, in mathematics, a ‘lemma’ (as in dilemma) is a minor, relatively-easy-to-prove claim which is often used as a stepping stone for proving major results.