LaTeX: Avoid new paragraph?
Asked Answered
H

8

12

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?

Holp answered 21/8, 2009 at 13:36 Comment(3)
Isn't adding a single character per \todo the least irritating solution we could get?Olia
voyager: No, I don't want to add any characters. The best we can do is to have a command (say \consume) that consumes the whitespace leading to it, so that I could redefine \todo to use \consume.Holp
There's \unskip to remove the last horizontal space, but the paragraph separator is a whole different story.Jodeejodhpur
V
13

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.

Viper answered 21/8, 2009 at 16:10 Comment(0)
S
12

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.

Superabound answered 24/8, 2011 at 3:54 Comment(0)
L
4

Try this:

Some text.
%
\todo{make note}
Landmark answered 21/8, 2009 at 13:38 Comment(3)
Adding a % between everything is obviously very irritating. Anything else?Holp
@Paul Biggar Clearly, you and I have different tolerances. ;-)Roselba
@Sinan Ünür: Well, I have to do it everywhere. That's why I asked for a command to consume whitespace.Holp
S
3

may be you shouldn't leave new line between the text and the todo note or just comment it

Some text.
%
\todo{make note}
Symptomatology answered 21/8, 2009 at 13:39 Comment(5)
Adding a % between everything is obviously very irritating. Anything else?Holp
not sure if this would work but if you want to leave new line between text and note you could try adding a backspace character in front of the todo command \b\todo{make note}Symptomatology
Just leave out the blank line completely? The only way for latex to start a new paragraph is a blank lineChihuahua
well the asker seems to want to avoid new lines in the output, but leave those in the source code (may be for readability reasons)Symptomatology
Why not indent the \todo instead of leaving the blank line? That should be at least as readable.Typhoon
N
2

How about

Some text.
%
\todo{make note}
%
some more text
Nathanielnathanil answered 21/8, 2009 at 13:39 Comment(3)
Adding a % between everything is obviously very irritating. Anything else?Holp
There must be something wrong with me because I have been doing this since 1993 whenever I wanted to leave some space in the middle of a paragraph without LaTeX creating paragraphs. I was never motivated to even wonder if there is any other way of doing it.Roselba
@Sinan Ünür: Clearly, you lacked an important project to procrastinate on ;)Holp
S
2

Set \endlinechar=-1 to make empty lines have no effect. You will need to use \par to separate paragraphs, which I think is a bigger irritation than having to type % on separator lines, but that's what you're asking for.

Saks answered 14/9, 2009 at 18:23 Comment(2)
What I'm really asking for is the ability to say "the last blank line had no effect. But very interesting, thank you.Holp
I don't think that's going to be easy. When TeX has already taken the last blank line as a paragraph separator, it has finalized the previous paragraph and added it to the list of boxes for the page, and possibly decided that the page was full and called the output routine for the page. I hesitate to say that undoing this is an impossible request given the tricks that TeX wizards can do, but I do think you need to find someone intimately familiar with TeX to help you with this.Jodeejodhpur
F
1

How about keeping everything that still has work left to do inside \def tags, and then removing it and moving it into the document proper when there's no more work to do?

E.g.

\def \par1
{
It was the best of times, it was the
}

\def \par2000
{
"Repression is the only lasting philosophy. The dark deference of fear and slavery, my friend," observed the Marquis
}

\def \paridunno
{
The end
}

A Tale of Two Cities, by Charles Dickens

\par1
\todo{write a whole bunch of pages}
\par2000
\todo{Visit ghost of Christmas future, copy pages from finished book}
\paridunno
\todo{Think of a better ending}

That has the added benefit of giving you a \listoftodos both in the source literally, and

in the output.

Fanatical answered 31/1, 2011 at 5:39 Comment(0)
F
0

just include your \todo right in the middle of your text. no line break, no nothing.

blah blah blah text \todo{Do this now!} more text blah blah blah.

on my computer (win xp, miktex 2.7, texniccenter) this work fine, produces no line break, and puts the todo note in the margin. . .

Frankpledge answered 21/8, 2009 at 17:18 Comment(2)
I think the original questioner really wants to make the \todo visually distinctive in the source.Viper
with the specifier to the todo package, like \todo[inline]{to do text} it adds the to do in the margin with a line connecting it to the text... if you use the [inline] option it will take the whole line and put the background color to orange by default.Frankpledge

© 2022 - 2024 — McMap. All rights reserved.