0

I'm trying to create an environment that makes paragraphs or groups of paragraphs in my text visually distinct from the rest. I just want it to be clear what is the one and what is the other. Ideally adding or removing this environment will not actually move any text on the page (though I could live with some re-wrapping if it changes line widths) and it must never change the order of the text.

\begin{leftbar} (from framed) works visually well, but it messes up \footnote{...}s. Also if I understand correctly leftbar results in a float which can be typeset somewhere out-of-line (which my use can't tolerate) if that is needed to keep it on a single page. I want things to split across pages if needed, just like a \paragraph, \section or an empty environment would.

Example

Just for completeness sake; this repros from more or less exactly what the the second paragraph starts with:

\documentclass{article}

\usepackage{framed}

\begin{document} \begin{leftbar} Hello\footnote{to the}

World\footnote{we live in} \end{leftbar} \end{document}

The footnote mark shows up but there is no footnote text at the bottom of the page.


If there are no easy options for that, are there any other ways I can highlight a chunk of text that won't adversely affect layout?

I've tried tcolorbox but that pulls the footnotes inside the resulting box. colorbox looks like it can maybe do something useful to me, but I don't see how to apply it to the body of my environment


A few of the things I've tried that don't work and why:

These are just the ones that have been mentioned in answers or comments.

\footnotemark/\footnotetext (without numbers)

  • They produce incorrect numbers if more than one is placed in the same context.
  • They place the footnotes on the wrong page if the enclosing environment spills over to another page.
...
\begin{leftbar}
Hello\footnotemark
World\footnotemark
\end{leftbar}
\footnotetext{to the}
\footnotetext{we live in}
...

\footnotemark/\footnotetext (with numbers)

They are brittle and can generate incorrect result, even messing up other footnotes without breaking the compile:

...\footnote{First}
\begin{leftbar}
Hello\footnotemark[1]

World\footnotemark[2] \end{leftbar} \footnotetext[3]{WTF?!} \footnotetext[2]{to the} \footnotetext[1]{we live in} \footnote{Last} ...

\colorbox{C}{...}

Can't (as far as I can tell) be wrapped around the body of a \newenvironment.

\begin{mdframed}

The mdframed environment places the footnotes inside the resulting box and at the end of it, which can be in the middle of a page and on a different page than the footnote mark is on.

BCS
  • 251

3 Answers3

1

as with any box you can split up the mark and the floating text, lifting the text out of the box:

enter image description here

\documentclass{article}

\usepackage{framed}

\begin{document} \begin{leftbar} Hello\footnotemark

World \end{leftbar}\footnotetext{to the} \end{document}

David Carlisle
  • 757,742
  • Fails with multiple footnotes. Which is to say it behaves differently than the default solutions would without the environment. I was already aware, before I thought to post this question, that there are complex and brittle ways to make them work, but they are complex and brittle which don't get me what I'm asking for: a little highlighting without *ANY other effects*. -- (Please don't ask me to enumerate all the ways it should "just do the normal thing". If it has more impact on where text shows up than adding \paragraph{} at the top of an existing paragraph, it's not what I want.) – BCS Jan 01 '22 at 19:03
  • @BCS it doesn't fail, it just needs some care (you can use multiple \footnotematk and \footnotetext) however no worries I posted this as the least intrusive change as it uses your existing sidebar code, but you will probably get other answers giving alternative bars (or of course you could mark the paragraph in other ways such as an indent or font or color change.) Just leave it a bit and accept the answer that best fits your real use case. – David Carlisle Jan 01 '22 at 19:45
  • For my needs, "needs some care" is functionally the same as "fails", unless getting it wrong break the compile. (See the failing examples I added.) -- Before posting, I looked into ways to color a block of text, but none of them I have found can apply to the body of a environment. Just tweaking the font (what I had before I started playing with leftbar) doesn't stand out enough. – BCS Jan 01 '22 at 20:34
  • 1
    coloring the (foreground) color of an enviornment is trivial of course just \color{red} adding a page breakable background colour is a bit harder but tcolorbox (and other) packages c an handle that, but as I say it would be better for other answers to provide alternitved to theframed packagemm this was showing a way to go with that. No problem if you don't accept. – David Carlisle Jan 01 '22 at 21:02
  • If you do't want to add that to this answer, please add another answer? – BCS Jan 01 '22 at 21:30
1

Found this package on ctan. I hadn't go the chance to dig into it yet but it seems to solve your problem with the help of tcolorbox

\documentclass{article}

\usepackage{footnote} \usepackage[most]{tcolorbox}

\usepackage{lipsum}

\newtcolorbox{leftbar}{% boxrule=0pt, boxsep=0pt, left=28pt, breakable, enhanced, borderline west={3pt}{0pt}{black}, colback=white, colframe=white, }

\makesavenoteenv{leftbar}

\renewcommand{\thempfootnote}{\arabic{mpfootnote}}

\begin{document} \begin{leftbar} Hello\footnote{to the}

    World\footnote{we live in}
\end{leftbar}

\begin{leftbar} Hello\footnote{test}

World\footnote{testing}

\lipsum[1-10]

\end{leftbar}

\meaning\footnote \end{document}

Note that it will break the hyperlinks of the footnotes

Udi Fogiel
  • 3,824
0

With hyperref support :D

\documentclass{article}
\usepackage{framed}
%\usepackage{hyperref}
\usepackage{footnotehyper}
\makesavenoteenv{leftbar}

\begin{document} \begin{leftbar} Hello\footnote{to the}

World\footnote{we live in}

\begin{leftbar} Hello\footnote{to the X}

World\footnote{we live in Z} \end{leftbar} \end{leftbar} \end{document}