0

I'd like to create a command that will turn all of the text that follows into italics, but something isn't working. Where am I going wrong?

p.s.: I know I could do it differently, but it's important that it's really a command!

\documentclass[a4paper,11pt,draft]{report}
\usepackage[utf8]{inputenc}

\newcommand\Tom{\par\bigskip\noindent\hbox to35mm{Tom\hfil}\hangindent=35mm } \newcommand\Mary{\par\bigskip\noindent\hbox to35mm{Mary\hfil}\hangindent=35mm } \newcommand\action{\par\bigskip\noindent\itshape}

\begin{document}

\Tom Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum is simply dummy text of the printing and typesetting industry.

\action This is the action line to put into the new text

\Mary Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum is simply dummy text of the printing and typesetting industry.

\end{document}

enter image description here

David Carlisle
  • 757,742
Andy Toff
  • 105

1 Answers1

2

So long as you always follow the action directive with a blank line, you can do

\newcommand{\action}{} % to avoid overwriting an existing command
\def\action#1\par{\par\bigskip\noindent\textit{#1}\par}

Full example with other fixes:

\documentclass[a4paper,11pt,draft]{report}

\newcommand\Tom{\par\bigskip\noindent\makebox[35mm][l]{Tom}\hangindent=35mm } \newcommand\Mary{\par\bigskip\noindent\makebox[35mm][l]{Mary}\hangindent=35mm } \newcommand\action{} \def\action#1\par{\par\bigskip\noindent\textit{#1}\par}

\begin{document}

\Tom Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum is simply dummy text of the printing and typesetting industry.

\action This is the action line to put into the new text

\Mary Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum is simply dummy text of the printing and typesetting industry.

\end{document}

enter image description here

Alternative, but \action<text> must be followed either by a blank line or one among \Tom or \Mary.

\documentclass[a4paper,11pt,draft]{report}

\newcommand\Tom{% \par\bigskip\noindent\makebox[35mm][l]{Tom}\hangindent=35mm } \newcommand\Mary{% \par\bigskip\noindent\makebox[35mm][l]{Mary}\hangindent=35mm } \makeatletter \newcommand\action{% \begingroup \par\bigskip\noindent\itshape \def\par{\endgroup@@par}% } \makeatother

\begin{document}

\Tom Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum is simply dummy text of the printing and typesetting industry.

\action This is the action line to put into the new text \Mary Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum is simply dummy text of the printing and typesetting industry.

\end{document}

egreg
  • 1,121,712