This post, defines a comment command which can be used via escape strings. Is there a way to get a defined comment string to be reformatted in the pdf output somehow?
For example would it be possible to have something like...
\documentclass{article}
\usepackage{listings}
\lstset{basicstyle=\small\sffamily,
numbers=none,
frame=tb,
columns=fullflexible,
comment=[l]{#},
showstringspaces=false,
escapechar=&% char to escape out of listings and back to LaTeX
}
\begin{document}
\begin{lstlisting}
Hello # Comment 1
World # Comment 2
\end{lstlisting}
\end{document}
do the same thing as...
\documentclass{article}
\usepackage{listings}
\newcommand*{\Comment}[1]{\hfill\makebox[3.0cm][l]{$\triangleright$ #1}}%
\lstset{basicstyle=\small\sffamily,
numbers=none,
frame=tb,
columns=fullflexible,
showstringspaces=false,
escapechar=&% char to escape out of listings and back to LaTeX
}
\begin{document}
\begin{lstlisting}
Hello &\Comment{Comment 1}&
World &\Comment{Comment 2}&
\end{lstlisting}
\end{document}
by somehow defining the comment string & making commentstyle use the \Comment{} command?


\begin{minipage}can be placed inescapebeginand\end{minipage}inescapeend. – matexmatics Jan 02 '24 at 15:49Comment 10$. This is not possible in the second solution since it escapes to LaTeX so then this should be inputted asComment 10\$. Which solution is best depends on the situation. – matexmatics Jan 03 '24 at 11:09