I was inspired by the code of Ignasi in the following link:
Mark (highlight) a paragraph (\item{…}) with a squiggly line across several pages
I modified it to do the following command:
which draws #1 parallel lines with the same color #2 along the text in the left margin.
\documentclass{article}
\usepackage{lipsum}
\usepackage[most]{tcolorbox}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing,calc}
\newcommand{\mycolorbarmarg}[2]{
\newtcolorbox{mybox}[1][]{%
enhanced, blank, breakable,
overlay ={\foreach \t in {0,...,#1}{
\draw[decorate,ultra thick,#2] ([xshift=-3-\t mm]frame.north west)--([xshift=-3-\t mm]frame.south west);},
}}
\begin{mybox}
#3
\end{mybox}
}
\begin{document}
\lipsum[1]
\mycolorbarmarg{2}{red}{\lipsum[1-5]}
\end{document}
But this command cannot be called more than once, otherwise, the following error message appears:
! LaTeX Error: Command \mybox already defined.
Error when I call at least twice \mycolorbarmarg
\mycolorbarmarg{2}{red}{\lipsum[1-5]}
\mycolorbarmarg{2}{red}{\lipsum[1-5]}
From what I understand: the command \mycolorbarmarg wants to override the mybox command, which does not allow it!
The ideal would be a tcolorbox environment with parameters #1 (number of lines) and #2 (their color), something like this, but of course not correct code:
\documentclass{article}
\usepackage{lipsum}
\usepackage[most]{tcolorbox}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing,calc}
%%%%% something like this:
\newtcolorbox{mybox}[3]{%
enhanced, blank, breakable,
overlay ={\foreach \t in {0,...,#1}{ %
\draw[decorate,ultra thick,#2] ([xshift=-1-\t mm]frame.north west)--([xshift=-1-\t mm]frame.south west);},
}}
\begin{document}
\lipsum[1]
% for some environment like this :
\begin{mybox}[#1,#2]\lipsum[1]\end{mybox}
\lipsum[1]
\end{document}
I first thought of this which solves the calling problem but where a lot of newtcolorbox are created:
\documentclass{article}
\usepackage{lipsum}
\usepackage[most]{tcolorbox}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing,calc}
\newcounter{tmp}
\setcounter{tmp}{1}
\newcommand{\mycolorbarmarg}[2]{
\newtcolorbox{mybox\thetmp}[1][]{%
enhanced, blank, breakable,
overlay ={\foreach \t in {0,...,#1}{
\draw[decorate,ultra thick,#2] ([xshift=-3-\t mm]frame.north west)--([xshift=-3-\t mm]frame.south west);},
}}
\begin{mybox\thetmp}
#3
\end{mybox\thetmp}
\addtocounter{tmp}{1}}
\begin{document}
\lipsum[1]
\mycolorbarmarg{2}{red}{\lipsum[1-5]}
\mycolorbarmarg{1}{blue}{\lipsum[1]}
\mycolorbarmarg{3}{black}{\lipsum[1-5]}
\mycolorbarmarg{0}{green}{\lipsum[1]}
\end{document}
Creating so many \newtcolorbox bothers me... It would be much better to have an environment or command from the tcolorboxù package directly that would use #1and#2` as parameters!
While writing my request, analyzing my problem, and leafing through the instructions for the tcolorbox package, I found \renewtcolorbox and it allowed me to compose this which also works:
\documentclass{article}
\usepackage{lipsum}
\usepackage[most]{tcolorbox}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing,calc}
%%%%% necessary for renewtcolorbox to have something to redefine
\newtcolorbox{mybox}[1][]{
enhanced, blank, breakable,
overlay ={%
\draw[decorate,ultra thick,black] ([xshift=-3 mm]frame.north west)--([xshift=-3 mm]frame.south west);},
}
%%%%% a command width \renewtcolorbox
\newcommand{\mycolorbarmarg}[2]{
\renewtcolorbox{mybox}[1][]{%
enhanced, blank, breakable,
overlay ={\foreach \t in {0,...,#1}{
\draw[decorate,ultra thick,#2] ([xshift=-3-\t mm]frame.north west)--([xshift=-3-\t mm]frame.south west);},
}}
\begin{mybox}
#3
\end{mybox}
}
\begin{document}
\lipsum[1]
\mycolorbarmarg{2}{red}{\lipsum[1-5]}
\mycolorbarmarg{1}{blue}{\lipsum[1]}
\mycolorbarmarg{3}{black}{\lipsum[1-5]}
\mycolorbarmarg{0}{green}{\lipsum[1]}
\end{document}
I prefer this but it's also not a tcolorbox environment with #1 and #2 as parameters.
Do you know if it is possible to make such an environment with tcolorbox?
I would like to use \begin{mybox}[#1,#2]\lipsum[1-]\end{mybox}
with #1 for the number of lines, and #2 for their color?


