3

I would like to include into a "traditional" text document an environment that mimics the graphical style of basic text on mobile phones: author 1 text left adjusted, on red blocks with rounded corners; author 2 text right adjusted, on green blocks with rounded corners, and so forth. Something with a syntax similar to this:

\begin{phonetext}
\authorleft{my text}
\authorright{your text}
\authorleft{my next text}
\end{phonetext}

The ideal would be to be able to choose colors of the backgrounds (e.g., red on left, green on right) and other font size and related information.

I don't need the ability to include photos, video frames, audio recording icons, posting date and time, and such, but perhaps someone else would use such options.

1 Answers1

6

enter image description here

\documentclass{article}
\usepackage{tcolorbox,varwidth}

\newenvironment{phonetext}{}{}

\newcommand\authorleft[1]{%
\begin{flushleft}\tcbox[colback=blue!50]{%
\begin{varwidth}{.7\textwidth}\raggedright#1\end{varwidth}}%
\end{flushleft}%
}
\newcommand\authorright[1]{%
\begin{flushright}\tcbox[colback=red!50]{%
\begin{varwidth}{.7\textwidth}\raggedleft#1\end{varwidth}}%
\end{flushright}%
}

\begin{document}
\begin{phonetext}
\authorleft{my text}
\authorright{your text}
\authorleft{my next text}
\authorright{your text
your textyour textyour textyour textyour textyour text
your textyour textyour textyour textyour textyour text
}
\end{phonetext}
\end{document}
David Carlisle
  • 757,742