1

Using verbatim (not Verbatim) for transcribing handwritten documents.

I spend a lot of time transcribing wills, deeds, letters and other handwritten documents. In doing this I use the verbatim environment, mainly to allow me to place words exactly where they need to be as well as for fitting long lines within the framework of the page width.

I've worked out ways (using many helpful tips from this site, Thanks!) around verbatim's limitations to allow things like superscript, crossed through words and footnotes for references as I'll demonstrate in my minimal working examples (MWE) below but I have run up on a limitation of only being able to incorporate two catcodes at a time per verbatim environment group.

Is there anybody who could provide me with a method to incorporate more of these in a verbatim environment? A mwe of the method used would be -very- much appreciated.

For other reasons I can't use Verbatim in my efforts.

    \documentclass[12pt]{memoir}
    \usepackage{verbatim}
    \usepackage[normalem]{ulem} %used to enable the use of strike out text via \sout{striked out text}
    % Footnote treatment, This keeps footnotes flush and aligned to the left.
    \setlength{\footmarkwidth}{1.7em} % if your footnotes go into the hundreds, you need at least 1.7em 
    \setlength{\footmarksep}{0em} 
    \footmarkstyle{#1.\hfill} % this will give you plain numbers for your notes 
    \begin{document}
    \noindent First Example: 
    \noindent Escaped Footnote and Superscript within a verbatim environment:
    \begingroup{
    {\catcode`?=\active
    \def?!#1!{\footnote{#1}}
    {\catcode`+=\active
    \def+!#1!{\textsuperscript{#1}}
    \tiny\begin{verbatim}
    This is an example of a +!superscript! with subsequent escaped footnotes in a verbatim 
    environment?!See the First Example!
    \end{verbatim}
    \normalsize
    }}
    \normalsize
    \noindent
    Second Example: 
    \noindent
    Escaped Footnote and sout from the ulem package to line through a word within a 
    verbatim environment:
    \begingroup{
    {\catcode`?=\active
    \def?!#1!{\footnote{#1}}
    {\catcode`+=\active
    \def+!#1!{\sout{#1}} 
    \tiny\begin{verbatim}
    This is an example of a +!line of text! group of words being crossed out with 
    subsequent escaped footnotes in a verbatim environment?!See the Second Example!
    \end{verbatim}
    \normalsize
    }}
    \normalsize
    \end{document}

This yields the following (note: inserting the code block in this message body above required me to slightly modified some of the line placements but shouldn't matter much) enter image description here

I'd like to be able to create a verbatim environment where I can incorporate escaped footnotes, superscript, strike-through, tall curly braces and many other components found in old handwritten documents ALL into one environment. All help greatly appreciated. Thanks!

2
  • What's the problem in using fancyvrb and Verbatim?
    – egreg
    Apr 11 '20 at 15:46
  • That looks rather hilarious. Wouldn't it be much easier to use \raggedright and to force newlines with \\ outside verbatim? Apr 11 '20 at 15:46
3

Do you need verbatim at all?

\documentclass{article}
\usepackage{alltt}
\usepackage[normalem]{ulem}
\usepackage{xparse}

\ExplSyntaxOn

\NewDocumentEnvironment{hand}{}
 {
  \trivlist\ttfamily\footnotesize\raggedright\item
 }
 {
  \endtrivlist
 }

\NewDocumentCommand{\?}{m}
 {
  \str_case:nn { #1 }
   {
    {!}{ \gentexuser_footnote:w }
    {+}{ \gentexuser_sout:w }
    {@}{ \gentexuser_textsuperscript:w }
   }
 }

\cs_new_protected:Npn \gentexuser_footnote:w #1 ! { \footnote{#1} }
\cs_new_protected:Npn \gentexuser_sout:w #1 + { \sout{#1} }
\cs_new_protected:Npn \gentexuser_textsuperscript:w #1 @ { \textsuperscript{#1} }

\ExplSyntaxOff

\setlength{\textheight}{3cm} % just to make a smaller picture

\begin{document}

\begin{hand}
This is an example of a \?@superscript@ with subsequent escaped footnotes in a verbatim 
environment\?!See the First Example!

This is an example of a \?+line of text+ group of words being crossed out with 
subsequent escaped footnotes in a verbatim environment\?!See the Second Example!
\end{hand}

\end{document}

enter image description here

7
  • Nice! What other operators are there besides !, + and @ for this? Are there any others?
    – gentexuser
    Apr 11 '20 at 16:39
  • @gentexuser I defined each of them. You can add to the list, using the same scheme.
    – egreg
    Apr 11 '20 at 16:51
  • Right, I realize that. I was asking what characters are useable to make new definitions. Some (like `$') I think wouldn't be able to be used.
    – gentexuser
    Apr 11 '20 at 16:54
  • @gentexuser You can use whatever character you want.
    – egreg
    Apr 11 '20 at 17:00
  • 1
    @gentexuser \hspace*{#1}, perhaps.
    – egreg
    Apr 11 '20 at 23:12
1

Here, I directly adapt the OP's verbatim approach. I make it so that + is a two-parameter active macro. The first parameter defines the operation and the 2nd parameter denotes the argument. Thus, +s!superscript! with an s is a superscript, +x!subsequent! with an x is a strikeout, and +f!See the First Example! with an f is a footnote.

 \documentclass[12pt]{memoir}
    \usepackage{verbatim}
    \usepackage[normalem]{ulem} %used to enable the use of strike out text via \sout{striked out text}
    % Footnote treatment, This keeps footnotes flush and aligned to the left.
    \setlength{\footmarkwidth}{1.7em} % if your footnotes go into the hundreds, you need at least 1.7em 
    \setlength{\footmarksep}{0em} 
    \footmarkstyle{#1.\hfill} % this will give you plain numbers for your notes 
    \textheight 2in
    \begin{document}
    \noindent Example: 
    \noindent Escaped Footnote, Superscript AND strikeout
      within a verbatim environment:
    \begingroup{
    {\catcode`+=\active
    \def+#1!#2!{\ifx s#1\textsuperscript{#2}\else
                \ifx x#1\sout{#2}\else
                \ifx f#1\footnote{#2}\fi\fi\fi}
    \tiny\begin{verbatim}
    This is an example of a +s!superscript! with +x!subsequent! escaped footnotes in a verbatim 
    environment+f!See the First Example!
    \end{verbatim}
    \normalsize
    }
    \end{document}

enter image description here

If one needs a way to escape a + into the document, then active + could be defined as

\def+#1!#2!{\ifx s#1\textsuperscript{#2}\else
            \ifx x#1\sout{#2}\else
            \ifx f#1\footnote{#2}\else
            \ifx +#1\char`+\fi\fi\fi\fi}

In this case ++!! will produce a + in the output.

0

Interestingly, with @egreg 's solution, multi-character macro delimiters are allowed.

If I add another case condition, choosing a (more or less) unlikely-to-occur sequence like spp,

    {spp}{ \gentexuser_spelling:w }

and define the matching command as

\cs_new_protected:Npn \gentexuser_spelling:w #1 spp { #1\textsuperscript{[spelling?]} }

and then invoke the \? macro with

\?{spp}Qwertuspp

with the first occurrance of the spp delimiter grouped within braces so as to appear as a token when presented to the macro,

then the result is:

qwertu

(It doesn't have to be in the hand environment, either.)

To have the delimiter characters appear as themselves, group them in braces to hide them from the scanning:

qwertu with spp

There could be use-cases for such a technique (e.g., shorthands without catcode changes?).

MWE

\documentclass{article}
%\usepackage{alltt}
\usepackage{xcolor}
\usepackage[normalem]{ulem}
\usepackage{xparse}

\let\olddot=\.

\ExplSyntaxOn

\NewDocumentEnvironment{hand}{ +b}
 {
%  \trivlist\ttfamily\footnotesize\raggedright\item
  \trivlist\raggedright\item
  #1
  \endtrivlist
 }
 {
 }

\NewDocumentCommand{ \? } { m }
 {
  \str_case:nn { #1 }
   {
    {!}{ \gentexuser_footnote:w }
    {+}{ \gentexuser_sout:w }
    {@}{ \gentexuser_textsuperscript:w }
    {;}{ \gentexuser_emphfd:w }
    {-}{ \gentexuser_arrows:w }
    {zy}{ \gentexuser_testxx:w }
    {z}{ \gentexuser_testz:w }
    {rq}{ \gentexuser_testrq:w }
    {spp}{ \gentexuser_spelling:w }
   }
 }


\RenewDocumentCommand{ \. } { m }
 {
  \str_case:nn { #1 }
   {
    {*}{ \gentexuser_hash:w }
   }
 }


\cs_new_protected:Npn \gentexuser_footnote:w #1 ! { \footnote{#1} }
\cs_new_protected:Npn \gentexuser_sout:w #1 + { \sout{#1} }
\cs_new_protected:Npn \gentexuser_textsuperscript:w #1 @ { \textsuperscript{#1} }
\cs_new_protected:Npn \gentexuser_emphfd:w #1 ; { {\large\textbf{#1}} }
\cs_new_protected:Npn \gentexuser_arrows:w #1 - { $\rightarrow$#1$\leftarrow$ }
\cs_new_protected:Npn \gentexuser_testxx:w #1 zy { ~ABC#1XYZ~ }
\cs_new_protected:Npn \gentexuser_testz:w #1 z { \textit{~zzz#1ZZZ~} }
\cs_new_protected:Npn \gentexuser_testrq:w #1 rq { {\color{blue}rq-Start: [{\bfseries#1}] :rq-End} }
\cs_new_protected:Npn \gentexuser_hash:w #1 * { +++#1+++ }
\cs_new_protected:Npn \gentexuser_spelling:w #1 spp { #1\textsuperscript{[spelling?]} }

\ExplSyntaxOff



%\setlength{\textheight}{3cm} % just to make a smaller picture

\begin{document}

\begin{hand}
This is an example of a \?@superscript@ with subsequent escaped footnotes in a verbatim 
environment\?!See the First Example!

This is an example of a \?+line of text+ group of words being crossed out with 
subsequent escaped footnotes in a verbatim environment\?!See the Second Example! And some \?;Emphfd text; as well.

And a \?+y{\?@x{\?;combo;}x@}y+.
And a \?+ycomboy+. Some \?-arrows and {-} text-

And \?{zy}xxx qwerty qwerty non-zy \?zUIOPz non-z

This is rq test: some \?{rq}text more textrq and outside rq.

\?{spp}Qwertuspp

\end{hand}

Format is \verb|\?{rq}text more textrq|.


\olddot a \.*b*

To obtain \?{spp}Qwertuspp, type \verb|\?{spp}Qwertuspp|.

And \verb|\?{spp}Qwertu{spp}xyzspp| produces: \?{spp}Qwertu{spp}xyzspp

\end{document}

Your Answer

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

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