Skip to content

Instantly share code, notes, and snippets.

@zr-tex8r
Created August 15, 2012 09:57
Show Gist options
  • Save zr-tex8r/3358339 to your computer and use it in GitHub Desktop.
Save zr-tex8r/3358339 to your computer and use it in GitHub Desktop.
An example of \ifnum`{=0\fi trick
% defqverb.sty
%%<*> \begin{defqverb}\CS<content>\end{defqverb}
% Makes \CS a macro that expands to the token list that is obtaned
% by full-expanding <content> in verbatim except \, {, and }.
% Here a newline character is converted to \par.
\def\defqverb#1{%
\xx@obeylines
\let\do\@makeother \xx@specials
\gdef\xx@finale{\let#1\xx@g@tempa}%
\xdef\xx@g@tempa{\ifnum`}=\z@\fi
}
\def\enddefqverb{%
\ifnum`{=\z@\fi}%
\aftergroup\xx@finale
}
\def\xx@specials{\do\ \do\$\do\&\do\#\do\^\do\_\do\%\do\~}
\begingroup\endlinechar\m@ne
\catcode13=\active
\gdef\xx@obeylines{\catcode13=\active \def^^M{\noexpand\par}}%
\endgroup
%% EOF
% test-defqverb.tex
\documentclass{article}
\usepackage{defqverb}
\newcommand\Test[1]{TEST[#1]}
\begin{defqverb}\Sample
\Test{#%$%#}
OK!
\end{defqverb}
\begin{document}
\show\Sample % show the meaning of \Sample
\Sample
\end{document}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment