0

I want to have some code (or package, or documentclass) that I can put in the header of the Latex document so that when compiling it reads certain commands in verbatim.

For example: all cross references like \cref \eqref etc should be displayed in verbatim if I turn that code on, but if I remove it, I compile the document including these control sequences. Ideally that would work for the inline math environment, too.

It feels like their must be an easy way to do, yet I am unable to find it.

UPDATE: (found decent workaround) So far I have been able to achieve a slightly more sophisticated workaround using ideas from here: Is there a way to produce \cite{xx} as it is in the generated PDF file?. I have a proofread.sty that looks like this

\AtBeginDocument{
  \catcode`_=12
  \begingroup\lccode`~=`_
  \lowercase{\endgroup\let~}\sb
  \mathcode`_="8000
}
\usepackage{twoopt}
\renewcommand{\foo}[1]{\textbackslash foo\{#1\}}
\renewcommand{\footwoopt}[3][\empty][\empty]{\textbackslash foo[#1][#2]\{#3\}}

for all command foo that I have. The first part solves problems with entering math mode if there are underscores in labels. (see Underscore in textmode vs mathmode)

The twoopt package and the associated control \footwoopt deals with potential optional arguments.

I am not entirely happy with this solution (since I still have to redefine all handles, the math thing is anoying, and I am afraid it is not very robust), but for now that works.

Some background: I want to hand the paper to someone that operates in MS Word. If she suggests changes (using MS Word track cahnges), I want to copy paste entire paragraphs back into the latex file. I am aware that Latex/Word compatibility is not the best, but there is no other way.

I am looking for an efficient way to get comments on the text into latex without losing crossreferences or control sequence from the copy-pasting exercise.

My workaround so far is flagging all in line commands putting \$ in front of it and then replacing them one by one afterwards. But that seems ineffecient.

  • It sounds like you want to \string everything when in proof mode, and not when in final mode: \documentclass{article} \newcommand{\prm}{\string}%proof %\newcommand{\prm}{}%final \begin{document} \prm\part{Part Title} \prm\section{Section Text} \end{document}. Detokenizing the whole document is possible but loses formatting (lines, paragraphs, ..), so not practical. – Cicada Feb 26 at 12:36
  • @Cicada: I was playing around with this, it is close to, but not yet ideal. Ideally, I would get \section{Section Text} as the output. Instead I get sectionSection Text. The closest I got so far was using the \renewcommand{\command}[1]{\textbackslash command\{#1\}} option. Yet there I have two problems: 1. if there are optional arguments (more than 1 in particular) it seems to get messed up. 2. if I had e.g. \section{section_text} I cannot get around the math interpretation of section_text – johaschn Feb 26 at 13:52
  • I have updated the question. – johaschn Feb 26 at 14:06
  • The on-off switch-nature of the task implies a grouping, which in turn implies a 'bracketing', either hard-coded per command, or a loop identifying the command (from \ to final }. Hard-coded wrapper example: \documentclass{article} \newif\ifprm \prmtrue \newcommand{\prm}{\string}%proof \newcommand\verbit[1]{\ifprm\detokenize{#1}\else#1\fi} \begin{document} \catcode{=12\catcode}=12\relax\prm\part{Part Title}\catcode{=1\catcode}=2 \verb+\section{Text 1}+ \detokenize{\section{Text 2}} \verbit{\section{Text 3}} \prmfalse\verbit{\section{Text 3a}}\end{document} – Cicada Feb 27 at 12:45
  • Getting a tick to display as a tick is a bit tricky: \catcode``{=12. – Cicada Feb 27 at 12:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.