6

Wanting to highlight parts of my text, intended to be read at second reading, by an inexpensive method in packages, I want to set up an environment that would put points at the beginning and end of the line, preferably at the margins of the environment. I obviously want to be able to include in this environment to create all kinds of texts or mathematical objects, like figures, theorems, footnotes ... in particular boxes produced with tcolorbox and some other environments... so the solution must be not based on any package I think, and especially not using tcolorbox or another package producing boxes !

I give an example of what I want to create, which I made by adding \dotfill, at the beginning and at the end of the text, while adding points at the beginning and end of the line thanks to \hfill. enter image description here I actually want to create a, say \vdotfill{text}, environment, based on the idea of the \dotvfill command, included in the answer of the following question vertical dotfill and then put my text between \dotfill up and down, and between some \vdotfill between right and left. Any ideas ?

2 Answers2

8

Yes, do not reinvent the wheel:

mwe

\documentclass{article}
\usepackage{lipsum}
\usepackage[most]{tcolorbox}
\newtcolorbox{dottedenvironment}{enhanced,
boxrule=0pt,boxsep=1em,colback=white, arc=3mm, frame hidden,
borderline={1pt}{2pt}{red!30!black,dotted}}
\begin{document}

\begin{dottedenvironment}
\lipsum[2]  
\end{dottedenvironment}

\end{document}

Edit: As stated in the comments, It seems a requeriment that boxes should be breakable even nested. I do not know an automatic approach and I think that is not a good idea (*), but manually you can break a nested tcolorbox

(*) Note that enforce breakable option is a bit insane.

mwe2

\documentclass{article}
\usepackage[paperwidth=8cm,paperheight=8cm]{geometry}
\usepackage{ltablex}
\usepackage{lipsum}
\usepackage[most]{tcolorbox}
\newtcolorbox{dottedenvironment}{enhanced,enforce breakable, boxrule=0pt,boxsep=1em,colback=white, arc=3mm, frame hidden,
borderline={1pt}{2pt}{red!30!black,dotted}}
\def\dummytext{The key message for success is to keep it simple. }
\def\moretext{\dummytext\dummytext\par}
\begin{document}
\begin{dottedenvironment}
\moretext
\begin{dottedenvironment}
\dummytext
\tcbbreak
\moretext\end{dottedenvironment}
\tcbbreak
\end{dottedenvironment}
\end{document}
Fran
  • 80,769
  • Sorry but your answer is not useful for complicated objects in my text, like figures, and it's known that tcolorbox refuses the floats... I edit my question to be more precise. Thank you – Faouzi Bellalouna Apr 29 '18 at 21:32
  • 1
    @FaouziBellalouna I know that tcolorbox refuses a floats inside it (it have no any sense do that) but a floats do not refuse include inside a tcolorbox (or two, or more) with figures, a tabular, or whatever you want, so ... where is the problem? – Fran Apr 29 '18 at 22:01
  • Moreover, tcolorbox could be itself a float object (page 76 of manual). – Fran Apr 29 '18 at 22:08
  • Recall that my aim was to highlight some parts of my text, which can contain several mathematical objects, like figures, theorems, footnotes ... in particular boxes produced with tcolorbox and some other environments, like I've precized. There's several problems if we want to insert float in tcolorboxes... I'll edit my question another time to precize more. Thanks – Faouzi Bellalouna Apr 30 '18 at 04:24
  • @FaouziBellalouna You should maybe take a minute and try to think about why floats cannot be inside a tcolorbox. – Henri Menke Apr 30 '18 at 06:06
  • @HenriMenke Excuse me but I'm not very technician in Latex, but I had to solve several problems when insiding floats in tcolorbox, what I use for my theorems and such.. Imagine if I have to inside tcolorboxes in tcolorb oxes ! – Faouzi Bellalouna Apr 30 '18 at 06:46
  • @Fran In particular, I have several breakable boxes produced with tcolorbox in my text, and we can't include breakable boxes in each other.. – Faouzi Bellalouna Apr 30 '18 at 16:44
  • @FaouziBellalouna Nested breakable boxes? That is a duplicate of https://tex.stackexchange.com/questions/420406/tcolorbox-it-is-possible-to-put-breakable-boxes-behind-each-other-overlap but my suggestion is not to try to do it with tcolorbox or whatever, but follow the "keep it simple" principle. However, note that \tcbbreak allow break a nested tcolorbox manually (even nested). – Fran Apr 30 '18 at 21:49
  • @Fran Finally I accept your answer, after edit. I've tried it on my own tcb-boxes, and could play with the option enforce breakable of your dottedenvironment, and the command \tcbbreak. It only remains the problem that all this could not be automated.. but it can be done with a little of attention. Thanks – Faouzi Bellalouna May 01 '18 at 04:51
  • I tried to play with the commands left=-3mm,right=-3mm,extrude right by=3mm,extrude left by=3mm, to obtain the original pagination, and at this moment, the command \tcbbreak has no effect. Why and how can I make it available with these kind of options ? Thanks – Faouzi Bellalouna May 01 '18 at 05:18
  • @FaouziBellalouna I added these options in my last MWE (just after enforce breakable) and \tcbbreak still work, so your problem seem more complex than that. Anyway I would look for a solution based on contents design to avoid break anything except (very occasionally) some main boxes. Note that even the tcolorbox manual warn you against this option that exist for backward compatibility and "usually gives you a mess of shattered boxes" . – Fran May 01 '18 at 07:43
  • Yes the behaviour of dottedenvironment for me with this option is as said the doc of tcolorbox, For an unbreakable box, \tcbbreak is identical to insert \par, i.e. it just starts a new paragraph. – Faouzi Bellalouna May 01 '18 at 11:13
2

ConTeXt can do this easily using textbackground. You can also include floats (which will not be surrounded by dots because they could appear elsewhere).

\startuseMPgraphic{dottedframe}
begingroup;
  for i=1 upto nofmultipars :
    draw ( llcorner multipars[i]
      -- lrcorner multipars[i]
      -- urcorner multipars[i]
      -- ulcorner multipars[i]
      -- cycle )
      enlarged (EmWidth,EmWidth)
      dashed withdots ;
  endfor ;
endgroup;
\stopuseMPgraphic

\definetextbackground
  [DottedFrame]
  [mp=dottedframe,
   location=paragraph,
   before={\blank[2*big]}]

\starttext

\starttextbackground[DottedFrame]
Text and/or environments and/or equations

Text and/or environments and/or equations

Text and/or environments and/or equations

\startplacefigure[location=here,title={The famous Dutch cow}]
  \externalfigure[cow]
\stopplacefigure

Text and/or environments and/or equations

Text and/or environments and/or equations

Text and/or environments and/or equations
\stoptextbackground

\stoptext

enter image description here

Henri Menke
  • 109,596