6

I am experiencing an odd issue with \textit and \emph. I have a list from plaintext and want to format it. Here is a minimum example demonstrating my issue:

\documentclass{article}

\begin{document}

\textit{
  (a)
  
  (b)
}

\end{document}

Results in:

an image which does not perfectly match the source text. The item (a) is repeated and (b) is not

Why? What is going on here?

9
  • 1
    remove the space between (a) and (b) in your code and it compiles normaly.
    – Roland
    Mar 16, 2021 at 7:27
  • 2
    Cool effect. But note the error message(s) you get: The argument of \textit must not contain an empty line or paragraph break. If you want to format more text, use {\itshape (a) \par (b)}. But LaTeX has better ways to produce lists (enumerate).
    – moewe
    Mar 16, 2021 at 7:30
  • @Roland - Your advice may make the immediate source of the error go away, but it does so at the cost of destroying the OP's intended formatting of the lines.
    – Mico
    Mar 16, 2021 at 7:34
  • 1
    @Mico where does he say what it should look like in the end? He asked: What is going on here? So for me the answer was the extra blank space is what is going on.
    – Roland
    Mar 16, 2021 at 7:41
  • 2
    It should be noted though that \\ and \newline are not the same as an empty line or \par. It is a good rule of thumb that one should not use \\ or \newline in the normal text body of a document: Paragraphs should be ended with an empty line (or \par if that is more convenient or appropriate) and within paragraphs there should be no forced line breaks with \\. (Of course \\ has its use in align or table environments and might be useful occasionally to avoid a bad line break. @Roland)
    – moewe
    Mar 16, 2021 at 16:47

1 Answer 1

14

The command \textit does not permit paragraph breaks in its argument, while all-blank lines cause paragraph breaks. You must be getting the following error message:

Runaway argument?
{ (a) 
! Paragraph ended before \text@command was complete.
<to be read again> 
                   \par 
l.9 }

Any lessons to be learnt? I'd say there are 2. First, don't ignore error messages. Second, to get your code to compile and perform the expected formatting, change the code chunk to

{\itshape
  (a)
  
  (b)
}
8
  • 2
    Thank you. This solves my problem. Do you know why it is like this though? It is unintuitive behaviour. For example in markup or html when you tag something as italic, it does not matter what kind of whitespace is included. Why does \textit treat whitespace differently than other characters?
    – Tom
    Mar 16, 2021 at 20:25
  • 1
    @Tom that is how the macro is defined. There are two ways to specify, say italics, for short texts \textit, for longer we have the switch \itshape. Same thing in html, its kinda ad practice to mark huge amounts of text inside a <em></em>, what is where we have css.
    – daleif
    Mar 16, 2021 at 21:47
  • 1
    @Tom: Think of how in html, you have inline elements versus block elements, which are meant to be used differently. Similarly, in LaTeX, some commands (like \emph) are designed to be used just within paragraphs, while others (usually environments) are meant to be used for longer sections of text. Mar 16, 2021 at 22:24
  • 2
    @Tom (La)TeX macros can be defined as taking 'long' or 'short' arguments. A long argument may contain paragraph end (\par or an empty line, which is converted to \par by TeX), but short arguments may not contain paragraph ends. Most explanations for that behaviour I have seen are about error detection: Many macros should only apply to a short stretch of text and not to whole paragraphs, so when the macro encounters a paragraph end, the user probably forgot a } to close the argument. ...
    – moewe
    Mar 17, 2021 at 7:44
  • 2
    ... Especially in the old days, when documents took long to compile, it was a good idea to have a rogue macro argument stop absorbing text at that point and throw an error, so that a user can stop the process or at least syntax checking has a chance of resuming afterwards. See for example the explanations in tex.stackexchange.com/q/1050/35864 and tex.stackexchange.com/q/39450/35864. ...
    – moewe
    Mar 17, 2021 at 7:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.