Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Is the following expected:

\documentclass{ltxdoc}
\begin{document}
\begin{verbatim}
% why is my percent sign gone?
\relax % not here
\end{verbatim}
\end{document}

missing percent

share|improve this question
    
ltxdoc is designed for dtx files where all the document is prefixed by % (including verbatim sections). –  David Carlisle Dec 19 '12 at 17:38
    
sigh... I recently started writing my dtx files in a manner which avoids to have to prefix all the lines with a % and this is why I only now realized the gobbling up of % signs at the beginning of lines. Doubling it %% leaves a survivor, which is fine for me. –  jfbu Dec 19 '12 at 18:07
add comment

1 Answer

up vote 8 down vote accepted

Class ltxdoc is a LaTeX class for typesetting the documentation in .dtx files. The class loads package doc that does most of the work including the definition of environment verbatim. In .dtx files the documentation lines usually starts with % to get ignored, when docstrip extracts the code. Instead of

\begin{verbatim}
% why is my percent sign gone?
\relax % not here
\end{verbatim}

the common use case is rather:

%\begin{verbatim}
%verbatim stuff that should be set without the
%percent signs at the start of the lines.
%\end{verbatim}

Therefore package doc modifies verbatim to ignore the percent sign at the start of a line. This is done by macro \check@percent that can be redefined locally:

\begingroup
\makeatletter
\let\check@percent\relax
\begin{verbatim}
% percent sign
\relax % and here
\end{verbatim}
\endgroup
share|improve this answer
    
Thanks, I had not paid attention to that redefinition of verbatim by doc until today when I converted an old dtx of mine to a new manner of setting up things where I still use ltxdoc (or scrdoc) but do not have to comment out the user-manual part, only the source code comments. Replacing % by %% gives me an acceptable work-around in the verbatim blocks and doing \let\check@percent\relax is still better, thanks. –  jfbu Dec 19 '12 at 18:12
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.