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

6
  • do you not need to enclose the text in curly brackets? E.g. \Tom{bla bla bla}
    – Plergux
    Commented Dec 15, 2020 at 10:07
  • 1
    Why do you say it isn't working? All text printed after \action is italic.
    – campa
    Commented Dec 15, 2020 at 10:09
  • I was just going to make the same comment as @campa, I added an image, all the text following \action is italic, so what is your question exactly? Commented Dec 15, 2020 at 10:09
  • 1
    @Plergux why braces? (they would not make any difference here, the commands are not defined to take an argument) Commented Dec 15, 2020 at 10:11
  • @DavidCarlisle I don't know. Which is why I asked.
    – Plergux
    Commented Dec 15, 2020 at 10:15

1 Answer 1

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}
1
  • 2
    Thank you Prof! This is really what I needed!
    – Andy Toff
    Commented Dec 15, 2020 at 11:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .