0

This is a follow-on question to a previous question on SE where it was suggested I create a new question.

Question: How to add lines (NOT a box) above and below non-verbatim text while maintaining access to ALL the traditional LaTeX text attributes including but not limited to fontfamily, fontshape (including italics, bolding, etc.), text color, etc.

This would include the ability to control the attributes of the lines above and below (together or separately) including but not limited to the line thickness, separation (above and/or below, together or separately) of the lines from the text, the color(s) of the lines (together or separately, single or progressive), and the fill color(s) (single or progressive) between the lines.

The numerous SE questions and answers I've reviewed do NOT meet the criteria I am looking for.

I've been able to meet a few of the above requirements using a combination of verbatim and fancyvrb in the following MWE:

\documentclass[varwidth]{article}
\usepackage{fancyvrb}
\usepackage{varwidth}
\usepackage{verbatim}
\usepackage{xcolor}

\begin{document}

{\centering
\begin{varwidth}{0.33\linewidth}
\begin{Verbatim}[commandchars=\\\{\}, fontfamily=courier, fontshape=it, numbers=none, frame=lines, framerule=0.7mm, framesep=3mm, rulecolor=\color{red}, fillcolor=\color{yellow}]
\textbf{Source} \textrightarrow \textbf{Migration}
\end{Verbatim}
\end{varwidth}
\par}

\end{document}

which results in:

enter image description here

However, if I try to substitute $\rightsquigarrow$ for \textrightarrow, I get the following LaTeX error:

Undefined control sequence.
<argument> Source $\rightsquigarrow 
                                    $ Migration
l.12 Source $\rightsquigarrow$ Migration

So for some reason, my attempt to insert the equivalent of an Inline Equation results in an error.

Also, my attempt to fill in the space between the two lines (e.g. fillcolor=\color{yellow}) fails when employing the above verbatim and fancyvrb code.

As outlined in the previous question on SE, I am attempting to reproduce the image that appeared in Dr. Thomas F. Sturm's sanitize-umlaut package for verbatim text:

Sturm's verbatim text

but for straightforward, run-of-the-mill, non-verbatim text (e.g. \textbf{}, $<equation>$, etc.).

I'm looking for a way to present text in the format (displayed above) in Sturm's documentation without the limitations I've encountered when using verbatim based code.

(Special thanks to egreg and Marcel Krüger for their assistance!)

Thanks for reading.

2
  • You have two separate issues here. First: the exact error you got is because \rightsquigarrow is a symbol that is not available in base latex. You have to load one of the symbol fonts to access it (e.g. amssymb). But even if you load the font, compilation will still fail, but this time because the math environment. Jul 14, 2022 at 1:24
  • The missing yellow color seems to be internal to the fancyvrb pacakge; if you replace frame=lines by frame=single the color shows up. If you replace by frame=leftline you see a bit of an issue: the color only shows between the left line and the start of verbatim text. Jul 14, 2022 at 1:40

1 Answer 1

2

Try this

\documentclass[varwidth]{article}
\usepackage{fancyvrb}
\usepackage{amssymb}
\usepackage{varwidth}
\usepackage{verbatim}
\usepackage{xcolor}

\begin{document}

{\centering
\begin{varwidth}{0.33\linewidth}
\begin{Verbatim}[commandchars=\\\{\}, codes={\catcode`\$=3},fontfamily=courier, fontshape=it, numbers=none, frame=lines, framerule=0.7mm, framesep=3mm, rulecolor=\color{red}, fillcolor=\color{yellow}]
\textbf{Source} $\rightsquigarrow$ \textbf{Migration}
\end{Verbatim}
\end{varwidth}
\par}

\end{document}

I made two changes, first is that I loaded \usepackage{amssymb} which provided the \rightsquigarrow symbol. Second is that I enabled math mode with the codes={\catcode`$=3} invocation, as explained in the fancyvrb documentation (section 4.1.17 on Catcode characters):

enter image description here


Actually, reading your question again: if you don't want to use verbatim, why use fancyvrb at all? If you just want to draw a box with some lines and colors, use something like mdframed instead. E.g. (I did my best to reproduce the settings you listed for the frames.)

\documentclass[varwidth]{article}
\usepackage{xcolor}
\usepackage{mdframed}
\usepackage{amssymb}
\usepackage{varwidth}

\begin{document}

{\centering
\begin{varwidth}{0.33\linewidth}
        \begin{mdframed}[skipabove=3mm,skipbelow=3mm,linecolor=red,backgroundcolor=yellow,linewidth=0.7mm,leftline=false,rightline=false]
                \textbf{A} $\rightsquigarrow$ \textsc{b}
        \end{mdframed}
\end{varwidth}
\par}

\end{document}

which produces

enter image description here


Looking at your previous question and the linked reference file, it seems that you want to use it to create an in-line highlighting effect? In that case you should use tcolorbox instead.

\documentclass{article}

\usepackage{amssymb}
\usepackage[skins]{tcolorbox}

\newtcbox{\myhl}{nobeforeafter,tcbox raise base,toprule=2pt, bottomrule=2pt, leftrule=0pt, rightrule=0pt, top=1mm,bottom=1mm,
  right=1pt,left=1pt,arc=0pt,boxsep=0pt,
  colframe=red,colback=yellow!10!white}

\MakeRobust\myhl


\begin{document}

Some text before \myhl{\textbf{A} $\rightsquigarrow$ \textsc{b}} some text after


\end{document}

Which gives

enter image description here

Update from OP: Latest image of what I was looking for from the beginning:

Latest lined text image.

Perfect! Thank you Willie Wong!!

8
  • I think you may have hit-the-nail-on-the-head...(if that is an OK expression to use) ... REALLY close to what I had imagined. Let me have a look at your answer to see how I can add the values as options for \myhl[ ... ] ! Perfect! Thank you! Jul 14, 2022 at 2:31
  • You are welcome. Be warned that the tcolorbox documentation is... very long. It took me about 5 minutes (and I sort of know what i am looking for) to find the keys to do that little bit of work I did. Have fun reading. :-) Jul 14, 2022 at 2:33
  • (The \MakeRobust call is in case you need to use the highlighting within a movable context, like \section{...}.) Jul 14, 2022 at 2:34
  • The option you already provided. e.g. toprule=2pt, bottomrule=2pt, leftrule=0pt, rightrule=0pt, top=1mm,bottom=1mm, right=1pt,left=1pt,arc=0pt,boxsep=0pt, colframe=red,colback=yellow!10!white ... are more than I was looking for ... linewidth, linecolor, backgroundcolor, spacingfromtext are the key options I'd like to be able to specify as part of \myhl[ ... ] ... Thank you again ... This may sound silly, but you might have the makings of a new package here ... as best I can tell, there is nothing out there that can do this ... Thanks again Jul 14, 2022 at 2:40
  • I was wondering what the \MakeRobust was all about ... Thanks! I REALLY think this could be a new, separate LaTeX package ... I've not see anything else like it anywhere!! Jul 14, 2022 at 2:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .