How to set section title based on section content?
![](https://secure.gravatar.com/avatar/8b5a3ee6fe397b9fd2f13c1ae4079f99.jpg?s=120&d=mm&r=g)
How to set section title based on section content? I have a document that has some structures like this: \starttext \startsection[title={Animals}] \event{\input knuth } \stopsection \startsection[title={Books}] \event{\input knuth } \stopsection \stoptext The event macro runs a bunch of conditionals, deciding which content to place inside the section. It places any one of neary 200 possible different types of content there. Sadly when I wrote the code, I thought generic titles would be okay. Now I realize I need to be more specific, giving titles that match the content inside. I could move the section titles inside the \event macro, but it means rewriting ~200 other macros. In other words, how do I define a section title by defining it somewhere in the content of the \event macro? \starttext \startsection[\whatistitle] %<-- would display "Neon Tetras" \event{\thetitleis{Neon Tetras}\input knuth } \stopsection \startsection[\whatistitle] %<-- would display "Detective Stories" \event{\thetitleis{Detective Stories}\input knuth } \stopsection \stoptext
![](https://secure.gravatar.com/avatar/74d41c3215dcdd377343cdc47311757c.jpg?s=120&d=mm&r=g)
Joel via ntg-context schrieb am 09.03.2024 um 16:01:
How to set section title based on section content?
I have a document that has some structures like this:
\starttext
\startsection[title={Animals}]
\event{\input knuth }
\stopsection
\startsection[title={Books}]
\event{\input knuth }
\stopsection
\stoptext
The event macro runs a bunch of conditionals, deciding which content to place inside the section. It places any one of neary 200 possible different types of content there.
Sadly when I wrote the code, I thought generic titles would be okay. Now I realize I need to be more specific, giving titles that match the content inside. I could move the section titles inside the \event macro, but it means rewriting ~200 other macros.
In other words, how do I define a section title by defining it somewhere in the content of the \event macro?
\starttext
\startsection[\whatistitle] %<-- would display "Neon Tetras"
\event{\thetitleis{Neon Tetras}\input knuth }
\stopsection
\startsection[\whatistitle] %<-- would display "Detective Stories"
\event{\thetitleis{Detective Stories}\input knuth }
\stopsection
\stoptext
When each section contains nothing except the \event command I would remove the section titles from the document itself and place them as part of the \event command. \define[1]\Event {\startsection[title={#1}] \input{knuth} \stopsection} \starttext \Event{Neon Tetras} \Event{Detective Stories} \stoptext Wolfgang
participants (2)
-
Joel
-
Wolfgang Schuster