# Are there alternatives to the percentage sign at the end of line/command?

Consider the following example, which contains the %-sign inbetween \only<2>{ .... my macro .... } and the subsequent minipage. If I leave it out, the spacing of the whole frame gets screwed. I understand what the % does and why it needs to be there. But I really would like to leave it out, because it would require to think about it and it would complicate the structure and organisation of my document. For that reason I'd like to keep the blank line.

Example in context of beamer: I'm using my custom environment to place tikz-objects somewhere on my frame and I'd like to place these code-snippets wherever I want within the frame environment, without thinking about what comes before or after, because actually the tikzpicture shouldn't effect any other content on the frame as it used as overlay. However the simple writing of the command does.

How can I make the inserting of these code snippets independent of the %-sign? Or is there a way to already include it inside the macro or environment?

\documentclass{beamer}

\usepackage{tikz}
\usepackage{siunitx}
\usepackage{kantlipsum}
\usepackage{environ}

\NewEnviron{tikzannotation}{%
\begin{tikzpicture}[overlay, remember picture, shift={(current page.south west)}]
\BODY
\end{tikzpicture}%
}

\begin{document}

\begin{frame}

\only<2>{%
\begin{tikzannotation}
\node[circle,fill = cyan, minimum width = 1.4cm, align=center,opacity=0.8,
text opacity = 1, font={\scriptsize},inner sep = 1pt
] at (11.2,7.2) {\SI{100}{\percent}\\real!};
\end{tikzannotation}%
}
% <----- this is important - but I want to leave it out!
\begin{minipage}[t]{\textwidth}
\kant[10]
\end{minipage}

\end{frame}

\end{document}


I hope this question does not appear to stupid. If I know what is the reason, I can fix it. But I'm worried about the cases where I don't realize.

## Comment

I'm aware that I could just leave out the blank line, but I want exactly that to make the code more readible. In a case where the reason for a blank line is to start a new paragraph I see the point. But in my case here it starts a new paragraph after nothing.

I basically wondered if there is a command like \pleaseIgnoreAllFollowingBlankLinesUntilTheNextGroup I could include inside my macro/environment. For example after all \begin{...} it does not matter if there are blank lines or not. Is there no way to adapt this behaviour?

## Further idea

As mentioned by David Carlisle, the problem is is caused by the creation of a new paragraph. So \let\par\relax could do the trick, as long as it happens inside a group. Is it advisable? Is there a way to get inside the environment definition?

\only<2>{%
\let\par\relax%
\begin{tikzannotation}%
\node[circle,fill = cyan, minimum width = 1.4cm, align=center,opacity=0.8,
text opacity = 1, font={\scriptsize},inner sep = 1pt
] at (11.2,7.2) {\SI{100}{\percent}\\real!};
\end{tikzannotation}%
}

• \ignorespaces and \ignorespacesafterend perhaps? But I rarely use them, I am pretty fine with % – user31729 Sep 6 '16 at 13:54
• you can leave out the % as long as you also leave out the blank line. A blank line is a paragraph break and implies vertical spacing, – David Carlisle Sep 6 '16 at 14:14
• A blank line means ”end of paragraph“; in some cases it is disabled, but I wouldn't do it here. – egreg Sep 6 '16 at 14:15
• You could use \empty instead ;-) – John Kormylo Sep 6 '16 at 14:20
• The line commented in your code as the one you want to omit is not inside the environment but after it. The % within the environment is not commenting a blank line (i.e. paragraph) but an end of line (i.e. space). – cfr Sep 6 '16 at 16:38

None of the % in the example shown are needed, they are only needed if you introduce white space into the source that you then have to hide, it is often preferable simply not to add the space that you do not want:

\documentclass{beamer}

\usepackage{tikz}
\usepackage{siunitx}
\usepackage{kantlipsum}
\usepackage{environ}

\NewEnviron{tikzannotation}
{\begin{tikzpicture}[overlay, remember picture, shift={(current page.south west)}]
\BODY
\end{tikzpicture}}

\begin{document}

\begin{frame}

\only<2>{\begin{tikzannotation}
\node[circle,fill = cyan, minimum width = 1.4cm, align=center,opacity=0.8,
text opacity = 1, font={\scriptsize},inner sep = 1pt
] at (11.2,7.2) {\SI{100}{\percent}\\real!};
\end{tikzannotation}}
\begin{minipage}[t]{\textwidth}
\kant[10]
\end{minipage}

\end{frame}

\end{document}


In particular a blank line always means a paragarph break and as shown implies vertical spacing. It is much clearer simply not to have the blank line than to have it but comment it out.

As always in TeX you can change the interpretation of end of lines so this does not happen, but a lot of code assumes that a blank line is end-of-paragraph so doing so would break more than it helps.

• But why does it happen? The overlay stuff shouldn't affect the typesetting. So there's a blank line - then the \only<2>{} which is essentially empty - then a blank line. So does the \only<2>{} have a similar effect to putting \mbox{} or something here? Otherwise, the multiple paragraph breaks shouldn't result in different spacing, even though there's some extras on slide 2, should they? That is, clearly they do, but why exactly? – cfr Sep 6 '16 at 14:53
• @cfr yes same as color specials any kind of whatsit is a real node and really messes up spacing, one of tex's hidden joys:-) – David Carlisle Sep 6 '16 at 14:58
• Thanks. That was my guess as I couldn't see any other reason. (Well, not in terms of colour specials, which I know nothing about, but \mbox{} is familiar!) – cfr Sep 6 '16 at 15:01
• @DavidCarlisle I understand what you want to say with your answer, but not leaving any space inbetween the code blocks just makes the code unreadable in some cases, so it does in my particular case. So I wondered if there is a command like \pleaseIgnoreAllFollowingBlankLinesUntilTheNextGroup I could include inside my macro. For example after all \begin{...} or sectioning commands it does not matter if there are blank lines or not. Is there no way to adapt this behaviour? – thewaywewalk Sep 6 '16 at 16:03
• @thewaywewalk tex syntax is optimised for document text and newlines are spaces and rendered as such, and blank lines are \par trying to fight that really just leads to pain and weird breakage all over the place. In a controlled environment you can make end of line be ignored (expl3 does that) you just need \endlinechar=-1 but trying to ignore the next \par up to some following environment is really making the code really fragile. – David Carlisle Sep 6 '16 at 17:43

You really do not want to \let\par\relax as suggested in your edit. Consider

\begin{frame}
\only<2>{%
\let\par\relax
\begin{tikzannotation}
\node[circle,fill = cyan, minimum width = 1.4cm, align=center,opacity=0.8,
text opacity = 1, font={\scriptsize},inner sep = 1pt
] at (11.2,7.2) {\SI{100}{\percent}\\real!};
\end{tikzannotation}%
}

\begin{minipage}[t]{\textwidth}
\kant[10]
\end{minipage}

\onslide<2>
A new paragraph.

Another.
\end{frame}


The \only<2>{...} does not limit the scope of the change on the affected slide. Thus, anything added on the second slide after that point will lack paragraphs. This is clear in the image above, where 2 intended paragraphs become a single paragraph.

Yes, you could put \let\par\relax within the environment, if you wished. That would limit the scope of the change to that environment.

\NewEnviron{tikzannotation}{%
\let\par\relax
\begin{tikzpicture}[overlay, remember picture, shift={(current page.south west)}]
\BODY
\end{tikzpicture}%
}


However, this will obviously have no effect outside the tikzannotation environment, so you will still need to remove or comment the blank line to prevent it from affecting the spacing on the second slide.

For the particular case in question, you could include the uncommented blank line, if desired, in a couple of ways.

For the example in the question, the simplest approach is just to use \onslide rather than \only. This does not prevent the blank line from affecting the spacing. But it does ensure that the effect on the spacing is the same for all slides in the frame. Whether this is enough depends on the details of the case, of course. But if the problem is simply jumping slide content, this approach is sufficient.

\begin{frame}
\onslide<2>{%
\begin{tikzannotation}
\node[circle,fill = cyan, minimum width = 1.4cm, align=center,opacity=0.8,
text opacity = 1, font={\scriptsize},inner sep = 1pt
] at (11.2,7.2) {\SI{100}{\percent}\\real!};
\end{tikzannotation}%
}

\begin{minipage}[t]{\textwidth}
\kant[10]
\end{minipage}
\end{frame}


A more sophisticated solution is to wrap the content of the slide in an overlayarea environment.

\begin{frame}
\only<2>{%
\begin{tikzannotation}
\node[circle,fill = cyan, minimum width = 1.4cm, align=center,opacity=0.8,
text opacity = 1, font={\scriptsize},inner sep = 1pt
] at (11.2,7.2) {\SI{100}{\percent}\\real!};
\end{tikzannotation}%
}
\begin{overlayarea}{\textwidth}{.8\textheight}

\begin{minipage}[t]{\textwidth}
\kant[10]
\end{minipage}
\end{overlayarea}
\end{frame}


I think no blank line is more readable, but your preferences obviously differ from mine since I find your code too spaced out for comfort anyway. (Not just yours - I habitually remove blank and commented lines from MWEs because I want to see as much code as possible on screen at once.)

Complete code:

\documentclass{beamer}
\usepackage{tikz}
\usepackage{siunitx}
\usepackage{kantlipsum}
\usepackage{environ}

\NewEnviron{tikzannotation}{%
\begin{tikzpicture}[overlay, remember picture, shift={(current page.south west)}]
\BODY
\end{tikzpicture}%
}

\begin{document}
\begin{frame}
\onslide<2>{%
\begin{tikzannotation}
\node[circle,fill = cyan, minimum width = 1.4cm, align=center,opacity=0.8,
text opacity = 1, font={\scriptsize},inner sep = 1pt
] at (11.2,7.2) {\SI{100}{\percent}\\real!};
\end{tikzannotation}%
}

\begin{minipage}[t]{\textwidth}
\kant[10]
\end{minipage}
\end{frame}
\begin{frame}
\only<2>{%
\begin{tikzannotation}
\node[circle,fill = cyan, minimum width = 1.4cm, align=center,opacity=0.8,
text opacity = 1, font={\scriptsize},inner sep = 1pt
] at (11.2,7.2) {\SI{100}{\percent}\\real!};
\end{tikzannotation}%
}
\begin{overlayarea}{\textwidth}{.8\textheight}

\begin{minipage}[t]{\textwidth}
\kant[10]
\end{minipage}
\end{overlayarea}
\end{frame}
\end{document}

• I like your idea with \begin{overlayarea}, but in my eyes it makes more sense to put the tikzannotations inside it and not the minipage? In this case one could apply zero height: \begin{overlayarea}{\textwidth}{0pt}%. After patching it with \AfterEndEnvironment{overlayarea}{\vspace{-1\baselineskip}} it comes close to something I can live with. What do you think? (I wonder why \vspace{-1\parskip} does not work though.) – thewaywewalk Sep 7 '16 at 7:44
• Well, I wouldn't. I often use overlayarea so I certainly wouldn't patch it like that. Why don't you use \onslide? Or add negative vertical space to tikzannotation if you want it in the environment? Personally, though, I wouldn't borrow trouble by doing any of this. I just wouldn't leave a blank line. That is, I wouldn't complicate the code in order to write the source differently, with all the attendant risks of side-effects. Beamer is already interfering a great deal with the output routine etc. – cfr Sep 7 '16 at 12:47
• Alright, fair points. I haven't used overlayarea so far. I don't want to use onslide as it still would alter the spacing compared to the case where there are no tikzannotations at all. Imagine I finished the complete typesetting of a frame and then decide to add some kind of annotation. I like to do that, without effects on the remaining content - like placing an smart art in MS Powerpoint. The overlayarea with the proposed patch could do that. Up to now I don't see any disadvantage. Including \vspace{-1\baselineskip} inside the tikz-environment does not have the same effect. – thewaywewalk Sep 7 '16 at 13:24