4

I am trying to add interlinear comments to a piece of text. I am currently using the solution here: How to do centered interlinear text in LaTeX

This involved defining a command

\newcommand\wrd[2]{%
  \leavevmode
  \vbox{\offinterlineskip
    \halign{%
      \hfil##\hfil\cr
      {\footnotesize\sffamily\vphantom{p}#1}\cr
      \noalign{\vskip\lineskip}%
      \vphantom{A}#2\cr
    }%
  }%
}

and running

\wrd{Tang Yin is a painter, poet and calligrapher, one of the "Four Masters of Ming Dynasty.}{Tang Yin entitled ‘Spring Slumber’ depicting a beautiful woman asleep.}

However, I run into trouble when my comment is more than one line long. Ideally, I would like the comment, even if it is multiple lines, to exist entirely above the line of text it is commenting on. I have tried to use expex, but I am not familiar enough with LaTeX generally to know how to do this simple task. Someone please help me.

My Problem

Edit: here is a small compilable example:

\documentclass[twoside,11pt]{memoir} % Font size

\usepackage{expex}

\newcommand\wrd[2]{% \leavevmode \vbox{\offinterlineskip \halign{% \hfil##\hfil\cr {\footnotesize\sffamily\vphantom{p}#1}\cr \noalign{\vskip\lineskip}% \vphantom{A}#2\cr }% }% } %----------------------------------------------------------------------------------------

\begin{document}

\lq What a lovely smell!\rq

He repeated the words several times over. Inside the room there was a painting \wrd{This is an interlinear comment but it is too long to fit above the line}. {by Tang Yin entitled ‘Spring Slumber’ depicting a beautiful woman asleep. under a crab-apple tree}, whose buds had not yet opened. The painting was flanked on either side by a pair of calligraphic scrolls inscribed with a couplet from the brush of the Song poet Qin Guan:

(on one side)
\vskip5pt


\end{document}

  • 1
    Welcome to tex.sx. It would be helpful if you expanded your example code to a small compilable example, starting with \documentclass and ending with \end{document}. Since different document classes are set up differently in ways that may affect what you are trying to do, it's really better not to have to guess. – barbara beeton Apr 24 '22 at 00:01
  • Thanks, I will do. (DONE) – Mason Wang Apr 24 '22 at 00:03

1 Answers1

4

It is not exactly clear the desired format, but here I introduce \longnote{width}{content}. I inserted a small red up-arrow at the point of the text where it is invoked. The approach is to top-lap a \parbox.

\documentclass{article}
\usepackage{stackengine,xcolor}
\newcommand\longnote[2]{%
  \makebox[0pt]{\textcolor{red}{$^{\uparrow}$}}%
  \tclap{\parbox[b]{#1}{\footnotesize\sffamily\strut#2}}%
}

\begin{document} However, I run into trouble when my comment is more than one line long. Ideally, I would like the comment, even if it is multiple lines, to exist entirely above the line of text it is commenting on. I have tried to use expex, but I am not familiar enough with LaTeX generally to know how to do this simple task. Someone please help me. However, I run\longnote{3in}{% This is top-lapped text. We will see if the text is long enough if the lines make space for more text. This is top-lapped text. We will see if the text is long enough if the lines make space for more text. This is top-lapped text. We will see if the text is long enough if the lines make space for more text. } into trouble when my comment is more than one line long. Ideally, I would like the comment, even if it is multiple lines, to exist entirely above the line of text it is commenting on. I have tried to use expex, but I am not familiar enough with LaTeX generally to know how to do this simple task. Someone please help me. \end{document}

enter image description here


SUPPLEMENT

Based on a comment by the OP, I provide an alternative below. First, I remove the \sffamily of the \longnote, so that the note remains typeset in the prevailing document font family (roman, in this case). Also, I choose here to fix the width of the note (at 3in), which had been the first argument to \longnote in the prior implementation. Here, instead, I make the first argument (now optional) a positional specifier for the top lap, either [l] (left), [c] (center-default), or [r] (right). While it would be ideal for the macro to know where on the text line it is being invoked from (it does not), this option will allow the user, after the fact, to avoid left/right margin overrun.

\documentclass{article}
\usepackage{stackengine,xcolor}
\newcommand\longnote[2][c]{%
  \makebox[0pt]{\textcolor{red}{$^{\uparrow}$}}%
  \toplap{#1}{\parbox[b]{3in}{\footnotesize\strut#2}}%
}

\begin{document} However, I run into trouble when my comment is more than one line long. Ideally, I would like the comment, even if it is multiple lines, to exist entirely above the line of text it is commenting on. I have tried to use expex, but I am not familiar enough with LaTeX generally to know how to do this simple task. Someone\longnote[r]{% This is top-lapped text. We will see if the text is long enough if the lines make space for more text. This is top-lapped text. We will see if the text is long enough if the lines make space for more text. } please help me. However, I run into trouble when my comment is more than one line long. Ideally, I would like the comment, even if it is multiple lines, to exist entirely above the line of text it is commenting on. I have tried to\longnote[l]{% This is top-lapped text. We will see if the text is long enough if the lines make space for more text. } use expex, but I am not familiar enough with LaTeX generally to know how to do this simple task. Someone please help me. \end{document}

enter image description here

  • This is awesome!! Is there any way to ensure the comment is bounded within the page? I am willing to sacrifice the centered-ness of the comment above the arrow to get this. Also, how can I make the fonts match? – Mason Wang Apr 24 '22 at 00:33
  • 1
    @MasonWang Please see my SUPPLEMENT which offers an alternative approach to the problem, trying to address some of your concerns. – Steven B. Segletes Apr 24 '22 at 01:03
  • Bless! I am very appreciative. – Mason Wang Apr 24 '22 at 02:01