Extra horizontal space from nothing

42 views
Skip to first unread message

Jon Callas

unread,
Nov 17, 2023, 2:34:25 PM11/17/23
to latexus...@googlegroups.com, Jon Callas
It's likely that the real answer to the issue I describe below is that I need to use the todo package. It's also likely that one of you will say, "nah, here's the thing you really want to use." The real thing I'm asking about is [La]TeX programming and trying to understand what's going on, just in case I ever go mad and want to write and release my own style package.

On with the show.

I wanted to make a command that allows me to put asides in a work in progress. A note that says, "I know this is awkward, let's fix it up" or "don't forget a paragraph dealing with the Mumble issue." Easy enough. I also wanted to have this have a form of conditional compilation on it as well, so I could --- I dunno what. I mean, it sounds good to be able to have an annotated version of a document and the release version, and I can really overthink it. Isn't that noble and sweet and slightly demented all at the same time?

So here's what I did. I took the etoolbox package, colors and highlighting, and threw them together to make this command (don't worry, full document to come):

\newcommand*{\aside}[1]{\iftoggle{ASIDE}
{\sethlcolor{gray82} {\sffamily\em
{\textcolor{pblue}{\hl{#1}}}
}}
{} %else
}

And that looks at a toggle (a boolean, via "etoolbox") and if the toggle is true, it takes the argument and gives it a light gray background, blue text that is sans serif italic. If the toggle is false, it does nothing -- it swallows the argument. If I put the aside inline of a sentence, there's extra whitespace when it's swallowed, not nothing. I think this is a property of {}, and trying \relax and a couple other suggestions doesn't make it be literally nothing.

If the answer is, "yeah, LaTeX wasn't intended to do #defines, you're just going to hurt yourself if you keep that up" then fine. It isn't what I want, but I know not to beat my head against the wall. 

With the asides in, I get (I hope this screenshot remains inline):

PastedGraphic-1.png

And with the toggle off, it produces:

PastedGraphic-2.png
I note that there's extra space in the first one before and after the aside, too. I don't mind that, I just think they're related.

Thus, I'm asking how to get what I want. An operational answer (go use package X) is fine. A programming answer of how to fix my code does not preclude the possibility that I would be much happier with some package.

Thanks for any and all help, including derisive laughter.

Full document below:

Jon

-----------

\documentclass[11pt]{article}

\usepackage{etoolbox}
\usepackage[usenames, dvipsnames]{xcolor}
\usepackage{soul}
\usepackage{graphics}

\definecolor{gray82}{gray}{0.82}
\definecolor{pblue}{cmyk}{1.00, 0.68, 0.00, 0.12}

\newtoggle{ASIDE}
\settoggle{ASIDE}{true}

\newcommand*{\aside}[1]{\iftoggle{ASIDE}
{\sethlcolor{gray82} {\sffamily\em
{\textcolor{pblue}{\hl{#1}}}
}}
{} %else
}

\begin{document}

Here's some sample text. \aside{A random aside in the midst of a line.} And some more text.

\aside{And here is an aside in the middle of some text as a paragraph all on its own. More text here, just so you get to see it taking up more than one line.}

Followed up by more text in a new paragraph.

\end{document}




Werner Grundlingh

unread,
Nov 17, 2023, 3:11:04 PM11/17/23
to LaTeX Users Group
You have a spurious space in your definition of \aside. Here's an alternative version that's a little more legible:

\newcommand*{\aside}[1]{%
  \iftoggle{ASIDE}{%
    % ASIDE is TRUE
    \sthlcolor{gray82}% Adjust highlight colour
    {\sffamily\itshape\color{pblue}\hl{#1}}% Set and style aside
  }{%
    % ASIDE is FALSE
  }%
  \ignorespaces
}

Note the use of % around line ends. It doesn't have to be that verbose, but for the example and the sake of this example, I've added some comments as well. See this for reference:
Reply all
Reply to author
Forward
Message has been deleted
0 new messages