TeX - LaTeX Asked by Romildo on July 29, 2021
I would like to try the lstsample
environment from the lstdoc
package, distributed with the listings
package.
For that I have written the following document:
documentclass{article}
usepackage{lstdoc}
usepackage{lipsum}
begin{document}
begin{lstsample}{}{}
color{blue}
lipsum[68]
end{lstsample}
end{document}
But it fails compilation with the message:
! Undefined control sequence.
lst@sampleInput ->MakePercentComment
catcode `^^M=10relax small lst@s...
l.10 end{lstsample}
What am I missing?
The lstdoc
package is primarily meant to be used in documents using the ltxdoc
class. That class loads the doc
class internally, which contains two macro definitions that are particularly relevant here:
defMakePercentIgnore{catcode`%9relax}
defMakePercentComment{catcode`%14relax}
Because the lstsample
environment needs those two macros, but the class you're using, article
, doesn't define them, LaTeX rightfully reports those macros as undefined when you attempt to compile your code. Adding the two definitions shown above in your preamble will solve that problem.
Also, one quirk of the lstsample
environment is that, for everything to work properly, all the lines within it must start by a %
followed by at least 4 spaces. Follow that rule and you shall be happy.
documentclass{article}
usepackage{lstdoc}
usepackage{xcolor}
usepackage{lipsum}
% The following definitions are taken from doc.dtx.
% see http://mirrors.ctan.org/macros/latex/base/doc.dtx
defMakePercentIgnore{catcode`%9relax}
defMakePercentComment{catcode`%14relax}
begin{document}
begin{lstsample}{}{}
% color{blue}
% lipsum[68]
end{lstsample}
end{document}
Correct answer by jub0bs on July 29, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP