Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Escape sequence in GenericCode #137

Closed
MikeEdu opened this issue Jun 9, 2022 · 6 comments
Closed

Escape sequence in GenericCode #137

MikeEdu opened this issue Jun 9, 2022 · 6 comments
Assignees
Labels
bug Issue or PR related to bugs in the documents or the build system. needs investigation Issue or PR dealing with (yet) unclear behavior.

Comments

@MikeEdu
Copy link

MikeEdu commented Jun 9, 2022

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 hochleitner self-assigned this Jun 10, 2022
@hochleitner hochleitner added needs investigation Issue or PR dealing with (yet) unclear behavior. bug Issue or PR related to bugs in the documents or the build system. labels Jun 10, 2022
@hochleitner
Copy link
Member

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:

% Code Enivornmente for Generic Code
\lstnewenvironment{GenericCode}[1][]
{\lstset{%
language={},
keepspaces=true,
commentstyle={},
texcl=false,
escapechar={},
escapeinside={},
#1}}
{}

Line 109 needs to be replaced with

escapeinside={/+}{+/},

@MikeEdu
Copy link
Author

MikeEdu commented Jun 11, 2022

Thank you!

@imagingbook
Copy link
Collaborator

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
Copy link
Member

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

Der Quellcode innerhalb dieser Umgebungen wird in der jeweiligen Programmiersprache interpretiert, wobei Kommentare erhalten bleiben. Diese Umgebungen können sowohl alleinstehend (im Fließtext) oder innerhalb von Float-Umgebungen (insbes.\ \texttt{program}) verwendet werden. Im ersten Fall wird der Quelltext auch über Seitengrenzen umgebrochen. Mit \verb!/+! ... \verb!+/! ist eine Escape-Möglichkeit nach \latex\ vorgesehen, die \va\ zum Setzen von Labels für Verweise auf einzelne Programmzeilen nützlich ist, \zB\ mit
%
\begin{quote}
\verb!/+\label{ExampleCodeLabel}+/!
\end{quote}

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
Copy link
Collaborator

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

@imagingbook
Copy link
Collaborator

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}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue or PR related to bugs in the documents or the build system. needs investigation Issue or PR dealing with (yet) unclear behavior.
Projects
None yet
Development

No branches or pull requests

3 participants