Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LaTeX: Avoid new paragraph?

I use the \todo command from the \todonotes package. I'd like to layout my source to put \todos separately from the previous paragraph:

Some text.

\todo{make note}

But I don't want \todo to start a new paragraph, or it screws up the spacing of the document.

Is there a command to avoid this?

If there were a command/package to consume the whitespace up to it, then I could redefine \todo to use it.

Edit: Adding a % between everything is obviously very irritating. Anything else?

like image 356
Paul Biggar Avatar asked Aug 21 '09 13:08

Paul Biggar


People also ask

How do you not start a new paragraph in LaTeX?

To start a paragraph without an indent, or to continue an interrupted paragraph, use \noindent . In the middle of a paragraph the \noindent command has no effect, because LaTeX is already in horizontal mode there. The \indent command's only effect is to output a space.

How do you stop LaTeX from tabbing?

Tab stops are set with the \= command, and \> moves to the next tab stop. Lines are separted by the \ \ command.

How do you skip lines in LaTeX?

Latex has come up with another way to add a line break or skip a line within the data. Therefore, we will be using the \break command in the code to do so. Before that, we have added new text data as a paragraph within the \begin and \end command as below. Execute and run this code file by using both arrow icons.


2 Answers

I have to agree with everybody else that you should probably just add the %, but I do find this question interesting. The problem is that as soon as LaTeX reads the empty line, it gets converted into the \par command, which ends the previous paragraph. At the beginning of \todo, that \par command has already been executed, and it's impossible to undo it (I think). So your only hope is to keep that \par from being inserted or from behaving like it normally does. If you want to prevent it from being inserted, you could try reading Chapter 8 of "The TeXbook", which should tell you how an empty line is converted to \par. Alternatively, you could try to make a solution based on the following kind of idea:

Some text.{\let\par\relax

\todo{make note}}

But watch out! You definitely don't want to globally change the behavior of \par, which is why I added an extra pair of curly braces (LaTeX commands are scoped, so the new definition of \par only takes effect within the group where the definition was made). Good luck.

like image 154
Anton Geraschenko Avatar answered Oct 25 '22 08:10

Anton Geraschenko


When the macro precedes the unwanted space, the % is not necessary if you make use of \@ifnextchar and \@gobble.

Consider something like (in the preamble, of course):

\makeatletter
\let\oldtodo\todo
\renewcommand\todo[1]{%
\oldtodo{#1}%
\@ifnextchar\par{\@gobble}{}}
\makeatother

That way, if you have something like:

\todo{Stuff}

Things

it will act the same as

\todo{Stuff}
%
Things

or

\todo{Stuff}
Things

You can generalize such things with a macro like

\makeatletter
\newcommand\gobblepars{%
    \@ifnextchar\par%
        {\expandafter\gobblepars\@gobble}%
        {}}
\makeatother

You can then use \gobblepars wherever you want to eat space (like after the todo). You can also re-define todo (as shown above) to automatically place a \gobblepars after it.

To handle the leading empty space. you can use \gobblepars too, but you have to be explicit. For example:

Some text\gobblepars

\todo{Stuff}

will prevent a \par from showing up between the two lines.

like image 33
TedPavlic Avatar answered Oct 25 '22 09:10

TedPavlic