The documentation for fancyvrb
claims: "you can build example environments (showing both result and verbatim text)...."
How?
For example, how should commands from fancyvrb
be used to construct a command such as \showboth
, shown in the "toy example" below, so that the output is what is shown as "desired" rather than the "actual" output I get?
Toy example
\documentclass{article}
\usepackage{fancyvrb}
\newcommand{\showboth}[1]{{#1} --- \protect\Verb!#1!}
\newcommand{\doit}[1]{also {#1}}
\begin{document}
Actual output: \quad \showboth{\doit{this}}
\bigskip
Desired output: \quad \doit{this} --- \verb!\doit{this}!
\end{document}
Actual application
In the actual application, I need such a command \showboth that can be used with an argument that comes from the argument passed by a surrounding command.
The purpose of this is to allow me to experiment systematically with various kinds of styling in my document design. For example, I want to see readily which of various styles I prefer for cross-referencing theorems and sections, as in the following source.
In that source, the package showboth
that's loaded consists simply of the code in the answer by @Ulrich Diez.
What I'd like is a 1-argument macro, whose argument is a label (thm:big
, e.g.), that produces the kind of complete itemize
environment shown (whose individual items in turn just call \showboth
with the various referencing commands, with those referencing commands in turn taking that label as their own argument.
\documentclass{article}
\usepackage{amsthm}
\usepackage{thmtools}
\usepackage{enumitem}
\usepackage{suffix}
\usepackage{showboth} % code from Ulrich Diez's answer
\usepackage[colorlinks=true,linkcolor=red]{hyperref}
\usepackage{cleveref}
% Tefererencing macros:
\newcommand{\thmref}[1]{\nameref*{#1} (\cref{#1})}
\newcommand{\thmnameref}[1]{\hyperref[{#1}]{\nameref{#1}}}
\WithSuffix\newcommand\thmnameref*[1]{\nameref*{#1}}
\newcommand*{\fullref}[1]{\hyperref[{#1}]{\cref{#1}} \nameref*{#1}}
\newcommand*{\unitref}[1]{\cref{#1} (\nameref*{#1})}
\newcommand*{\unitnameref}[1]{\hyperref[{#1}]{\cref{#1}} (\nameref*{#1})}
% Thorerem styles
\swapnumbers
\declaretheoremstyle[
headfont=\bfseries,
notefont=\bfseries,
headformat=\NAME\NUMBER\let\thmt@space\@empty\NOTE,
bodyfont=\mdseries\itshape,
]{thmstyle}
\makeatletter
\declaretheoremstyle[
headfont=\bfseries,
notefont=\bfseries, notebraces={}{},
headformat=\NUMBER\let\thmt@space\@empty\NOTE,
bodyfont=\mdseries\itshape,
]{namedthmstyle}
\makeatother
\theoremstyle{thmstyle}% default
\declaretheorem[name=Theorem,numberwithin=section]{theorem}
\theoremstyle{namedthmstyle}
\declaretheorem[style=namedthmstyle, name=Theorem,title = {},numberlike=theorem]{namedtheorem}
\begin{document}
\section{Stuff}\label{sec:stuff}
\begin{theorem}[refname=Theorem,name=Preliminary Result]\label{thm:prelim}
Notice this!
\end{theorem}
\begin{namedtheorem}[name=The Big Theorem]\label{thm:big}
Very important!
\end{namedtheorem}
\begin{theorem}\label{thm:another}
Another big result.
\end{theorem}
\begin{itemize}
\item \showboth!\thmref{thm:big}!
\item \showboth!\thmnameref{thm:big}!
\item \showboth!\thmnameref*{thm:big}!
\item \showboth!\fullref{thm:big}! % LITTLE USE!
\item \showboth!\nameref{thm:big} \cref{thm:big}!
\item \showboth!\nameref*{thm:big} \cref{thm:big}!
\item \showboth!\cref{thm:big}!
\item \showboth!\cref*{thm:big}!
\end{itemize}
\smallskip
\begin{itemize}
\item \showboth!\thmref{thm:prelim}!
\item \showboth!\thmnameref{thm:prelim}!
\item \showboth!\thmnameref*{thm:prelim}!
\item \showboth!\fullref{thm:prelim}! % LITTLE USE!
\item \showboth!\nameref{thm:prelim} \cref{thm:prelim}!
\item \showboth!\nameref*{thm:prelim} \cref{thm:prelim}!
\item \showboth!\cref{thm:prelim}!
\item \showboth!\cref*{thm:prelim}!
\end{itemize}
\smallskip
\begin{itemize}
\item \showboth!\thmref{thm:another}!
\item \showboth!\thmnameref{thm:another}!
\item \showboth!\thmnameref*{thm:another}!
\item \showboth!\fullref{thm:another}! % LITTLE USE!
\item \showboth!\nameref{thm:another} \cref{thm:another}!
\item \showboth!\nameref*{thm:another} \cref{thm:another}!
\item \showboth!\cref{thm:another}!
\item \showboth!\cref*{thm:another}!
\end{itemize}
\smallskip
\begin{itemize}
\item \showboth!\unitnameref{sec:stuff}!
\item \showboth!\unitref{sec:stuff}!
\item \showboth!\thmref{sec:stuff}!
\item \showboth!\thmnameref{sec:stuff}!
\item \showboth!\thmnameref*{sec:stuff}!
\item \showboth!\fullref{sec:stuff}! % LITTLE USE!
\item \showboth!\nameref{sec:stuff} \cref{sec:stuff}!
\item \showboth!\nameref*{sec:stuff} \cref{sec:stuff}!
\item \showboth!\cref{sec:stuff}!
\item \showboth!\cref*{sec:stuff}!
\end{itemize}
\end{document}
stringstrings
) gives a spurious space between\doit
and{this}
; both the first and second seem to treat the result of the command as math, thus typesetting\doit{this}
as also this.