0

Extreme TeX novice, sorry for the length of the example, I wasn't sure what packages were important to replicate the problems. I was trying to create a simple command that I could use to injected labeled comments into an existing document. My comment would be in text color blue and be prefixed with initials ('[XXX]' in this example)

\documentclass[12pt]{article}
\usepackage{cprotect}
\usepackage{amssymb, amsmath, bm, bbm}
\usepackage{adjustbox}

\usepackage{amsmath, amsfonts}
\usepackage{bm, bbm}
\usepackage{graphics, graphicx, color, epsf}
\usepackage{natbib}
\usepackage{xr, zref, hyperref}
\usepackage{etoolbox, siunitx}
%
\usepackage{xcolor}
%
\usepackage{scrextend}
%
\newcommand\xxx[1] {\newline\textcolor{blue}{[XXX] #1}}

\begin{document}
\title{A title}
\author{A person}
\maketitle
\section{A section}
Some section stuff
\xxx{a comment}
\begin{verbatim}
This is 
text that 
presented 'as-is'
\end{verbatim}
Some more text
\xxx{
abc
\begin{verbatim}
verbatim
\end{verbatim}
}
\end{document}

Generates:

line 37: Argument of \@xverbatim has an extra }. } 
line 37: Paragraph ended before \@xverbatim was complete. } 
line 37: Extra }, or forgotten \endgroup. } 
: Emergency stop. 
: Command \@footnotemark has changed.

I tried to define a newenvironment (not shown) used by the command, thinking that perhaps the 'command' couldn't handle nested content, but it didn't help.

  1. I'd like to understand what I have done wrong and how I might figure out such issues in the future.

  2. Find a concise summary of the TeX syntax (not LaTeX, just basic basic TeX).

  3. Understand how to get rid of that footnotemark warning. Is some package redefining that command?

5
  • 4
    Welcome to TeX.SX! Verbatim is complicated in all possible ways. In general, a verbatim command or environment will not work in the argument of another command. Aug 22, 2020 at 17:13
  • Are there alternatives to verbatim?
    – Dweeberly
    Aug 22, 2020 at 17:18
  • it depends, for your example you could just use \texttt{verbatim} to get that font but verbatim makes all the special characters non-special so \frac just prints \frac rather than making a fraction, that can not work in an argument. Aug 22, 2020 at 17:26
  • 1
    With “verbatim” I mean the entire concept of printing “as-is”, not the specific environment. You can, for example, do \newcommand\xxx{\begingroup\color{blue}[XXX]} and \newcommand\zzz{\endgroup}, then write \xxx before the environment and \zzz after. Or you can define \newenvironment{blueverbatim}{\color{blue}[XXX]\verbatim}{\endverbatim} and use blueverbatim instead Aug 22, 2020 at 17:27
  • 1
    unrelated but you almost certainly don't want to load epsf (unless you are writing this document in the 1980s) also \newline\textcolor looks wrong you should rarely need \newline Aug 22, 2020 at 17:28

1 Answer 1

2

You can probably use xparse's +v-type-argument for having LaTeX read and tokenize everything in verbatim-category-code-régime and then passing things to \scantokens for re-tokenization, but if you do this, then \xxx cannot be used within macro-arguments/macro-definitions/etc:

\documentclass[12pt]{article}
\usepackage{xparse}
%
\usepackage{xcolor}
%
\begingroup
\newcommand\xxx[1]{%
  \endgroup
  \newcommand\xxx{%
    \begingroup
    \catcode`\^^I=12 %
    \innerxxx
  }%
  \NewDocumentCommand{\innerxxx}{+v}{%
    \endgroup
    \textcolor{blue}{[XXX] %
    \begingroup
    \newlinechar=\endlinechar
    \scantokens{\endgroup##1#1}}%
  }%
}%
\catcode`\%=12\relax
\xxx{%}%

\begin{document}

\title{A title}
\author{A person}

\maketitle

\section{A section}

Some section stuff

\xxx{a comment}bla

\begin{verbatim}
This is 
text that 
presented 'as-is'
\end{verbatim}

Some more text

\xxx{%
abc
\begin{verbatim*}
verbatim
\end{verbatim*}
}%

Indenting is funny when nesting verbatim-environment in verbatim-argument:

\xxx{%
  abc
  \begin{verbatim*}
  verbatim
  \end{verbatim*}
}%

Indenting is funny when nesting verbatim-environment in verbatim-argument:

\xxx{%
  abc
  \begin{verbatim*}
  verbatim
    verbatim
\end{verbatim*}
}%

\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .