0

I have a command that returns a different word according to a predefined value.

\def\isPaper{0}
...
\newcommand{\paper}{
    \begingroup
        \def\True{1}
        \ifx\True\isPaper
            paper
        \else
            thesis
        \fi
    \endgroup
}

But when I use it, I get an extra white spaces in the text:

throughout this \paper.

ut this  thesis .

When I remove all formatting and indices and write the whole thing in one line, then the white spaces disappear.

\newcommand{\paper}{\begingroup\def\True{1}\ifx\True{\isPaper}paper{\else}thesis\fi\endgroup}

Is there a way to keep this command readable and not have the white spaces?

(this happens both when isPaper is 0 and 1)

F. Pantigny
  • 40,250
SIMEL
  • 185
  • 4
    put comments % to hide the ends of lines, eg {% not { which is {SPACE – David Carlisle Oct 27 '23 at 21:32
  • 1
    End of line in the source is interpreted as a space character, you need to add % at the ends of (at least) line 1, 3, 4, 5, and 7 of the definition. (But that will also mean that you will need to add an explicit space after the macro, i.e. \paper\ since spaces are gobbled after a macro.) There are also much simpler ways to implement what you're doing here. – Alan Munn Oct 27 '23 at 21:34
  • @AlanMunn, what is an example of a simpler way to implement this? I'm with just the basics of Latex. – SIMEL Oct 27 '23 at 22:02
  • @SIMEL One way would be toggles from the etoolbox package. If you don't want to add any packages, define a boolean: \newif\ifpaper, \papertrue or \paperfalse, and then \ifpaper paper\else thesis\fi. – Teepeemm Oct 27 '23 at 22:29
  • @Teepeemm, From what I understand it would require more words in the body of the text, which is counter productive. My goal is to have nothing more than \paper in the body or at most {\body} because of the space issue. – SIMEL Oct 28 '23 at 00:58
  • But you can define \paper to be that conditional and use it the same way you're currently using it. Similarly with etoolbox. You can keep using \paper, but these give you much simpler implementations of your command. – Teepeemm Oct 28 '23 at 01:32
  • @Teepeemm, I appreciate the effort, but I am not really sure how to implement this, and I don't see the advantage of this as defining \paper to be the conditional still leaves me with the space problem, which is the biggest flaw I see in my implementation. Thank you for your effort nonetheless. – SIMEL Oct 28 '23 at 01:42

0 Answers0