1

I'm using \newcommand and \ifdefined in the following way:

\documentclass[12pt]{article}
\usepackage{color}
\newcommand{\showcomment}{}
\newcommand{\scomment}[1]{\ifdefined\showcomment\textcolor{blue} {\small\bfseries[ #1 --someone ]}\else\fi}
\begin{document}
some content
\scomment{comment}
some content
\end{document}

enter image description here

In this way, I can uncomment \newcommand{\showcomment}{} to avoid showing inline comments in pdf. But the problem is that, when doing this, it will leave two spaces between some content:

enter image description here

If I comment out \scomment{comment}, only one space is showing between adjacent contents. But this is apparently not the desired way since there will be many of those commands.

Is there a way to achieve the same functionality while avoiding double spaces?

  • 2
    Now you're enjoying the new LaTeX 2e, why not update your syntax to remove obsolete font commands such as \bf? And it never did take an argument .... \small doesn't take an argument either. – cfr Jul 24 '18 at 3:35
  • 1
    I guess it would be more natural to define a boolean \if... (or an etoolbox toggle) directly instead of \ifdefined\showcomment. – moewe Jul 24 '18 at 14:50
4

I wouldn't trust this, myself. Why not use fixme or todonotes or one of the many other packages designed for this? You want to reinvent the wheel? OK. But, really, is your hexagonal design honestly going to do the make the cut? Sure, the round shape is old hat, a bit boring, what the old folks use, but, in the end, maybe the designer knew a thing or two about getting the job done?

\documentclass[12pt]{article}
\usepackage{xcolor}
\newcommand{\scomment}[1]{\ifdefined\showcomment\textcolor{blue}{\small\bfseries[ #1 --someone ]}\else\unskip\fi}
\begin{document}
some content
\scomment{comment}
some content

\newcommand{\showcomment}{}%
some content
\scomment{comment}
some content
\end{document}

spacing facilities

\bf, \it, \tt and the rest of it were made obsolete by the introduction of NFSS with LaTeX 2e and ought not be used with the LaTeX format. Some classes do not even continue to support them.

None of those commands or their current equivalents or any of the font size commands take arguments.

\small{hi} bye

is just the same as

\small hi bye

and will make the rest of your document use a smaller font size, until you change it back.

| improve this answer | |
  • The fix works for me! As for the two packages you mentioned (fixme and todonotes), do they support multiple users so that different comment styles are showing in a collaborative document? – chaonan99 Jul 24 '18 at 14:38
  • @chaonan99 From the fxime documentation: "FiXme provides support for collaborative annotating by allowing you to “register” several authors." But I'm sure todonotes can do a similar thing. – moewe Jul 24 '18 at 14:52
  • @chaonan99 I've never used todonotes, so I can't say, but fixme definitely does this. I've used the multiple-author-tracking myself and it worked great. – cfr Jul 24 '18 at 22:03
  • I'd recommend using the marginnote layout with fixme and setting innerlayout to something like noinnerlayout (don't have a pc with me), this has the advantage that now fxote can be used everywhere, at the cost of writing on top of each other if used twice on the same line (but there is counter measures for that). I use fixme for all document notes on projects that I edit and use it for author communication using the author key – daleif Jul 25 '18 at 6:47
  • @daleif Yes, that's similar to the approach I've used, too. – cfr Jul 25 '18 at 13:03
1

There are commands in LaTeX, like \label or \index, whose occurrence in the .tex-input should not affect the look of those passages of text that LaTeX is about to typeset while processing the \label-command or \index-command in question.

Internally these macros use \@bsphack..\@esphack in order to ensure that spaces after them will be ignored in case there also were spaces before them.

Unfortunately the algorithm gets disturbed when you have a sequence of \label- or \index-commands.

In the example below I implemented a variant which seems to not get disturbed.

Besides this I decided to implement forking depending on \showcomment being defined in a way which cannot be fooled by imbalanced \if../else/\fi within the argument of \showcomment.

\documentclass[12pt]{article}
\usepackage{color}

%--------------------------------------------------------
% This just draws a grid so you can with monospaced fonts
% like \texttt see the amount of horizontal spaces
%
% This is quick and dirty. Don't use it for produtive
% work.
%
% \uglygridphantom{<width>}{<height>}{<linecolor>}{<background color>}
%
\newcommand\uglygridphantom[4]{%
%  \leavevmode
  \rlap{%
    \vbox to 0cm{%
      \kern\dp\strutbox
      \kern-.5\baselineskip
      \noindent\fboxsep=0cm
      \setbox\csname @tempboxa\endcsname=\hbox{W}%   
      \kern-.5\wd\csname @tempboxa\endcsname
      \colorbox#4{%
        \vbox to \numexpr#2+1\relax\baselineskip{%
          \leaders\hbox{%
            \hbox to \numexpr#1+1\relax\wd\csname @tempboxa\endcsname{%
              \setbox\csname @tempboxa\endcsname=\hbox{W\kern-\fboxrule}%
              \leaders\hbox{%
                \textcolor#3{%
                  \rule{.5\wd\csname @tempboxa\endcsname}{\fboxrule}%
                  \rule[-.5\baselineskip]{\fboxrule}{\baselineskip}%
                  \rule{.5\wd\csname @tempboxa\endcsname}{\fboxrule}%
                }%
              }\hfill
            }%
          }\vfill
        }%
      }%
    }%
  }%
}
%--------------------------------------------------------



%\newcommand{\showcomment}{}
\makeatletter
\newcommand{\scomment}[1]{%
  \my@bsphack
  \ifdefined\showcomment
    \expandafter\my@esphack\expandafter\@firstofone
  \else
    \expandafter\my@esphack\expandafter\@gobble
  \fi
  {%
    \textcolor{blue}{%
      {%
        %% Turn off the font changes as they 
        %% disturb my nice little grid :-)
        %\small\bfseries\selectfont
        [ #1 --someone ]%
      }%
    }%
  }%
}
\newskip\mysavsk
\newcommand*\my@bsphack{%
  \relax
  \ifhmode\mysavsk\lastskip\@savsk\lastskip\@savsf\spacefactor\fi
}%
\newcommand*\my@esphack{%
  \relax
  \ifhmode
    \spacefactor\@savsf
    \ifdim\@savsk>\z@
      \ifdim\lastskip=\z@\nobreak\hskip\z@skip\fi
      \nobreak\hskip-\mysavsk
      \nobreak\hskip\mysavsk
      \ignorespaces
    \fi
  \fi
}%
\makeatother

\begin{document}
\frenchspacing
\parindent=0ex
\parskip=0ex

\let\showcomment=\UnDeFinED
\rmfamily\selectfont
Now\verb|\showcomment| is undefined:
\ttfamily\selectfont

\uglygridphantom{69}{2}{[rgb]{0.5059,0.5059,0.5059}}{[rgb]{0.9294,0.9294,0.9294}}%
some content
\scomment{commentA} \scomment{commentB}
\scomment{commentC} \scomment{commentD}
some content

\vspace*{2\baselineskip}
\def\showcomment{}
\rmfamily\selectfont
Now\verb|\showcomment| is defined:
\ttfamily\selectfont

\uglygridphantom{69}{2}{[rgb]{0.5059,0.5059,0.5059}}{[rgb]{0.9294,0.9294,0.9294}}%
some content
\scomment{commentA} \scomment{commentB}
\scomment{commentC} \scomment{commentD}
some content

\vspace*\baselineskip
\rmfamily\selectfont
I hope that did the trick.

\end{document}

enter image description here

| improve this answer | |

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.