Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Labels

I'm trying to reproduce the effect pictured here in LaTex. I would like to be able to label parts of a sentence to help my students with grammar.

Is something like this possible? I'm not aware of any packages that do this. {I wasn't sure what tag to give this; if tikz is wrong, please feel free to correct.}

Thanks for your help.

share|improve this question
1  
This could be done using tikzmark or a pstricks equivalent. There are many similar examples: for example How to draw markup language structure? and linked questions. Those solutions might help you get started. –  Paul Gessler May 16 at 15:53
    
I presume the ability to automatically line-wrap is a necessity? –  Steven B. Segletes May 16 at 16:21
2  
You could adapt the answers here tex.stackexchange.com/questions/125162/… –  David Carlisle May 16 at 16:27
    
There might be something useful at essex.ac.uk/linguistics/external/clmt/latex4ling. –  cfr May 16 at 17:02

1 Answer 1

This is not an ideal answer, but since I worked on it, I'll post it. (REVISED to provide two alternatives)

I took David's suggestion and reworked my answer from Rounded box around placeholder text that supports line breaking.

VERSION 1:

What are the drawbacks:

1) because of the way I continue the rule over spaces (using the length \afterspacelap), a negative side effect is that the overrule protrudes into the left margin for continued lines.

2) The label, passed as an argument, is \rlapped 2em to the right of the text marking. If there is not enough room, one can rekern to the left as I did with my "LINEBREAKING" label, but if that is not sufficient room, then there is no remedy.

3) The label does not break up the overline, as in the OP's photo, but only sits atop it.

The good news is that it does line break and paragraph break.

\documentclass{article}
\usepackage{censor}
\usepackage{stackengine}
\usepackage{xcolor}
\usepackage{scalerel}
\newlength\rlwd
\rlwd=.8pt

\makeatletter
\setstackgap{L}{9pt}
\def\stacktype{L}
\def\useanchorwidth{T}
\censorruledepth=\Lstackgap

\periodrlap=0pt\relax
\afterperiodlap=0pt\relax
\lletterlap=0pt\relax
\rletterlap=0pt\relax
\afterspacelap=1.0ex\relax

\renewcommand\censorrule[1]{%
\protect\textcolor{cyan}{\rule[\censorruledepth]{#1}{\rlwd}}%
}

\renewcommand\@cenword[1]{%
  \setbox0=\hbox{#1}%
  \stackon[0pt]{#1}{\censorrule{\wd0}}%
}

\def\censordot{\textcolor{cyan}{\rlap{\@cenword{\phantom{.}}}}.}

\def\endleft{\rule[\Lstackgap-3pt+.7\rlwd]{\rlwd}{3pt}}
\let\endright\endleft

\newcommand\marktext[2][]{%
\trlap[11pt]{\sffamily\bfseries\scriptsize\textcolor{cyan}{\hspace{2em}{\uppercase{#1}}}}%
\textcolor{cyan}{\llap{\smash{\endleft}}}%
\xblackout{#2}%
\textcolor{cyan}{\rlap{\smash{\endright}}}%
}

\makeatother
\parindent 0in
\parskip 1em
\begin{document}

This shows linebreaking capability: aaa aaa aaa aaa aaa aaa aaa
\marktext[\kern-13pt linebreaking]{bbb bbb bbb bbb. bbb bbb bbb bbb bbb bbb}
ccc ccc ccc ccc ccc ccc

Can this \marktext[phrase]{procedure go across paragraphs boundaries?

Why yes} it can.

But gaps can arise if glue is stretched too far.

\afterspacelap=1.7ex\relax
\marktext[sentences]{%
This tests marking a multiline block of text.  This tests marking a multiline block of text.
This tests marking a multiline block of text.  This tests marking a multiline block of text.
This tests marking a multiline block of text.}

\end{document}

enter image description here


VERSION 2:

This revised version has the virtue that it extends equally into both the left and right margins for wrapped lines, but it comes at a cost. The cost is that the leading and trailing ends of the blue overline are likewise extended by this amount,

\documentclass{article}
\usepackage{censor}
\usepackage{stackengine}
\usepackage{xcolor}
\usepackage{scalerel}
\newlength\rlwd
\rlwd=.8pt

\makeatletter
\setstackgap{L}{9pt}
\def\stacktype{L}
\def\useanchorwidth{T}
\censorruledepth=\Lstackgap

\periodrlap=.5ex\relax
\afterperiodlap=.5ex\relax
\lletterlap=.5ex\relax
\rletterlap=.5ex\relax
\afterspacelap=.5ex\relax

\renewcommand\censorrule[1]{%
\protect\textcolor{cyan}{\rule[\censorruledepth]{#1}{\rlwd}}%
}

\renewcommand\@cenword[1]{%
  \setbox0=\hbox{#1}%
  \stackon[0pt]{#1}{\censorrule{\wd0}}%
}

\def\censordot{\textcolor{cyan}{%
  \rlap{\@cenword{\phantom{.\hspace{\periodrlap}}}}}.}

\def\endleft{\rule[\Lstackgap-3pt+.7\rlwd]{\rlwd}{3pt}}
\let\endright\endleft

\newcommand\marktext[2][]{%
\trlap[11pt]{\sffamily\bfseries\scriptsize\textcolor{cyan}{\hspace{2em}{\uppercase{#1}}}}%
\textcolor{cyan}{\llap{\smash{\endleft}\hspace{\lletterlap}}}%
\xblackout{#2}%
\textcolor{cyan}{\rlap{\hspace{\rletterlap}\smash{\endright}}}%
}

\makeatother
\parindent 0in
\parskip 1em
\begin{document}

This shows linebreaking capability: aaa aaa aaa aaa aaa aaa aaa
\marktext[\kern-13pt linebreaking]{bbb bbb bbb bbb. bbb bbb bbb bbb bbb bbb}
ccc ccc ccc ccc ccc ccc

Can this \marktext[phrase]{procedure go across paragraphs boundaries?

Why yes} it can.

But gaps can arise if glue is stretched too far.

\periodrlap=.8ex\relax
\afterperiodlap=.9ex\relax
\lletterlap=.8ex\relax
\rletterlap=.8ex\relax
\afterspacelap=.8ex\relax
\marktext[sentences]{%
This tests marking a multiline block of text.  This tests marking a multiline block of text.
This tests marking a multiline block of text.  This tests marking a multiline block of text.
This tests marking a multiline block of text.}

\end{document}

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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