xetex – How to Insert Verbatim Section in Place of Teaser Figure in Acmart

acmartcharactersfigure-placementverbatimxetex

I would like to use a graphic built from monospaced characters as a teaser figure in an acmart document. Elsewhere in the document I've used verbatim sections inside of table*s to do this, creating figures made of characters that span the width of the page. The acmart format makes it tough to place anything between the author line and the abstract, though, anything I try to put there is instead placed on its own page at the beginning of the document before anything else appears.

Looking at the acmart.cls class file, I see that the insertion of the teaser figure section is implemented with these lines:

\def\@teaserfigures{}
\newenvironment{teaserfigure}{\Collect@Body\@saveteaser}{}
\long\def\@saveteaser#1{\g@addto@macro\@teaserfigures{\@teaser{#1}}}

Is there a way to put arbitrary content like a verbatim into this area? There could be other options as well, like putting a verbatim at the end of the authors list somehow, as long as it appears between the authors list and main text. I'm using Xetex specifically.

Below is code for a sample acmart document containing a working teaser. Below the working teaserfigure spec is a commented spec expressing what I want: a teaserfigure with a verbatim inside it. Try commenting out the working teaser and enabling the one with the verbatim and you'll see that trying to generate it will fail.

The teaser for the code below depends on an image called "sampleteaser.pdf," part of ACM sample content available in the /samples folder inside this zip file: ACM template file

\documentclass[sigplan,screen]{acmart}

\usepackage[utf8]{inputenc}
\usepackage{fontspec}
\usepackage{subcaption}
\usepackage{setspace}

\setcopyright{acmcopyright}
\copyrightyear{2023}
\acmYear{2023}
\acmDOI{XXXXXXX.XXXXXXX}

\acmConference[Conference]{Full Conference Name}{Date of}{Location}
\acmPrice{0.00}

\begin{document}

\title{Title}
\subtitle{And a subtitle}

\author{Author Name}
\email{[email protected]}

\begin{abstract}
Abstract goes here.
\end{abstract}

\keywords{keywords, go, here}

%% A "teaser" image appears between the author and affiliation
%% information and the body of the document, and typically spans the
%% page.

%% This teaser works:
\begin{teaserfigure}
  \includegraphics[width=\textwidth]{sampleteaser}
  \caption{Seattle Mariners at Spring Training, 2010.}
  \Description{Enjoying the baseball game from the third-base
  seats. Ichiro Suzuki preparing to bat.}
  \label{fig:teaser}
\end{teaserfigure}

%% This teaser is broken:
%% \begin{teaserfigure}
%%   \begin{verbatim}
%%     abc
%%     def
%%   \end{verbatim}
%% \end{teaserfigure}

%%
%% This command processes the author and affiliation and title
%% information and builds the first part of the formatted document.
\maketitle

\section{Introduction}
Intro goes here.

%% Here's a working verbatim as part of the article text:
\begin{verbatim}
  abc
  def
\end{verbatim}

\section{Conclusion}
Another section.

\end{document}
\endinput

A follow-up question: How can I apply styling to the fancy verbatim section? I'm trying this:

\setlength{\lineskiplimit}{\maxdimen}
\setlength{\lineskip}{-0.1pt}
\begin{SaveVerbatim}[fontsize=6pt]{TeaserVerb}
  content
  goes
  here
\end{SaveVerbatim}
\begin{teaserfigure}
\UseVerbatim{TeaserVerb}
\end{teaserfigure}
\setlength{\lineskiplimit}{0pt}
\setlength{\lineskip}{1pt}

But it's not working. The lineskip changes are needed because I'm using box-drawing characters inside the section; there shouldn't be any lineskip so that there are no breaks between rows. I've also put a font size in there, I've also tried fontsize=small and that doesn't make a change either.

Best Answer

You can use SaveVerbatim from fancyvrb.

\documentclass[sigplan,screen]{acmart}

%\usepackage[utf8]{inputenc} % <--- NOT with fontspec
\usepackage{fontspec}
\usepackage{subcaption}
%\usepackage{setspace} % <--- ? Why?

\usepackage{fancyvrb} % <--- For SaveVerbatim

\setcopyright{acmcopyright}
\copyrightyear{2023}
\acmYear{2023}
\acmDOI{XXXXXXX.XXXXXXX}

\acmConference[Conference]{Full Conference Name}{Date of}{Location}
\acmPrice{0.00}

\begin{document}

\title{Title}
\subtitle{And a subtitle}

\author{Author Name}
\email{[email protected]}

\begin{abstract}
Abstract goes here.
\end{abstract}

\keywords{keywords, go, here}

%% A "teaser" image appears between the author and affiliation
%% information and the body of the document, and typically spans the
%% page.

\begin{SaveVerbatim}{TeaserVerb}
abc \LaTeX is {} nice
def
\end{SaveVerbatim}
\begin{teaserfigure}
\UseVerbatim{TeaserVerb}
\end{teaserfigure}

\maketitle

\section{Introduction}
Intro goes here.

%% Here's a working verbatim as part of the article text:
\begin{verbatim}
  abc
  def
\end{verbatim}

\section{Conclusion}
Another section.

\end{document}

Don't load inputenc if you plan to use LuaLaTeX or XeLaTeX (and fontspec). By the way utf8 has been the default also for pdflatex for a few years.

I'd not load setspace with acmart.

Beware that verbatim modes respect initial spaces on lines, as shown in the example (see the verbatim in the body).

enter image description here

EDIT

How to do the special formatting? Here's a possible way, that keeps the setting of \lineskiplimit and \lineskip local.

\documentclass[sigplan,screen]{acmart}

%\usepackage[utf8]{inputenc} % <--- NOT with fontspec
\usepackage{fontspec}
\usepackage{subcaption}
%\usepackage{setspace} % <--- ? Why?

\usepackage{fancyvrb} % <--- For SaveVerbatim

\newsavebox{\verbteaserbox}

\setcopyright{acmcopyright}
\copyrightyear{2023}
\acmYear{2023}
\acmDOI{XXXXXXX.XXXXXXX}

\acmConference[Conference]{Full Conference Name}{Date of}{Location}
\acmPrice{0.00}

\begin{document}

\title{Title}
\subtitle{And a subtitle}

\author{Author Name}
\email{[email protected]}

\begin{abstract}
Abstract goes here.
\end{abstract}

\keywords{keywords, go, here}

%% A "teaser" image appears between the author and affiliation
%% information and the body of the document, and typically spans the
%% page.

\setbox\verbteaserbox=\vbox{
\setlength{\lineskiplimit}{\maxdimen}%
\setlength{\lineskip}{0pt}%
\setlength{\parindent}{0pt}%
\fontsize{6}{0}\selectfont
\begin{BVerbatim}
abc \LaTeX is {} nice
def
abc \LaTeX is {} nice
def
abc \LaTeX is {} nice
def
abc \LaTeX is {} nice
def
abc \LaTeX is {} nice
def
\end{BVerbatim}
}
\begin{teaserfigure}
\usebox{\verbteaserbox}
\end{teaserfigure}

\maketitle

\section{Introduction}
Intro goes here.

%% Here's a working verbatim as part of the article text:
\begin{verbatim}
  abc
  def
\end{verbatim}

\section{Conclusion}
Another section.

\end{document}

enter image description here