PROBLEM
Build an environment to put some text in some boxes that should be both breakable across a page and adapt to text width. Unfortunately, packages mdframed
and tcolorboxes
have the first option, but not the second, because it seems that varwidth
makes them uncomfortable.
PROPOSED SOLUTION
Build two environments.
WORKING EXAMPLE
\documentclass{article}
% General document formatting
\usepackage[margin=0.7in]{geometry}
\usepackage[parfill]{parskip}
\usepackage[utf8x]{inputenc}
\usepackage{lmodern,textcomp}
\usepackage[italian]{babel}
% Related to math
\usepackage{amsmath,amssymb,amsfonts,amsthm}
% just for this example
\usepackage{blindtext}
% lists
\usepackage{enumerate}
\renewcommand{\labelitemii}{$\ast$}
\renewcommand{\labelitemiii}{--}
% colors
\usepackage{xcolor}
\definecolor{myblue}{RGB}{0,32,155}
\definecolor{myred}{RGB}{192,0,0}
\definecolor{mygray}{RGB}{68,84,106}
\definecolor{myred2}{RGB}{180,4,38}
\definecolor{myorange}{RGB}{238,132,104}
\definecolor{mygreen}{RGB}{26,152,80}
% url
\usepackage{hyperref}
% useful comments
\usepackage{varwidth}
\usepackage{mdframed}
\mdfdefinestyle{basemdstyle}{%
skipabove=1em,
skipbelow=1em,
innertopmargin=0.75em,
innerbottommargin=0.75em
}
\newmdenv[style=basemdstyle]{baseemph}
% breakable
\newcommand\lredemph[1]{%
\begin{baseemph}[fontcolor=myred]%
{#1}%
\end{baseemph}}
% width-adaptive
\newcommand\redemph[1]{\fbox{%
\begin{varwidth}{\textwidth}%
{\textcolor{myred}{#1}}%
\end{varwidth}%
}\par}
\begin{document}
\Blindtext
\lredemph{\textbf{this will go across pages.} \Blindtext}
\redemph{this will be just as large as the text}
\end{document}