Digital-Media / HagenbergThesis

Hagenberg LaTeX Thesis Template
Other
197 stars 47 forks source link

Escape sequence in GenericCode #137

Closed MikeEdu closed 2 years ago

MikeEdu commented 2 years ago

Is there any reason, why the GenericCode environment has no escape sequence like /+ ... +/?

It would be nice, if this feature is also available in the GenericCode environment. Espacially because the escape sequence is mentioned in the tutorial, but it is not mentioned that there is an exception for any code environment.

hochleitner commented 2 years ago

Just had a look into it. I don't see any reason why there shouldn't be an escape sequence for the GenericCode environment enabled as well. I'll include that for the next iteration after testing it.

For now you can just add it yourself in hgblistings.sty:

https://github.com/Digital-Media/HagenbergThesis/blob/9f9b9c38f9db802adffcff5c88623594ce6a2250/dev/latex/hgblistings.sty#L101-L111

Line 109 needs to be replaced with

escapeinside={/+}{+/},
MikeEdu commented 2 years ago

Thank you!

imagingbook commented 2 years ago

The reason for not allowing this escape sequence in the GenericCode environment is that it makes the encapsulated code "non-generic" in the sense that such code may not contain the escape literals themselves ...

hochleitner commented 2 years ago

Okay, that does make sense, although it's probably a rare case. Let's keep it that way then and I'll adapt this line here

https://github.com/Digital-Media/HagenbergThesis/blob/9f9b9c38f9db802adffcff5c88623594ce6a2250/documents/HgbThesisTutorial/chapters/abbildungen.tex#L684-L688

to state that GenericCode is an exception to this. I will also add a wiki page on how to add this in case this comes up again.

imagingbook commented 2 years ago

Rare indeed, but needed e.g. to show the sample code for how to use that escape sequence :,-)

imagingbook commented 2 years ago

As mentioned yesterday, all code environments in hgblistings.sty accept optional arguments that are forwarded to the underlying \lstset command. Thus, to use GenericCode with the usual (or some other) LaTeX escape sequence you can just write, e.g.,

\begin{GenericCode}[escapeinside={/+}{+/}]
double alpha = 1.0;         /+($\alpha$)+/
double beta = 3.14;         /+($\beta$)+/
\end{GenericCode}