Can anyone shed some light on this? I have an interesting problem involving the "There's no line here to end" error.
EDIT: Variables. I did not think to include this as I thought there was only one way to declare variables.
\newcommand{\@emptymacro}{}% Used to test against an empty macro
\newcommand{\@name}{}
\newcommand{\name}[1]{\renewcommand{\bfseries \@name{#1}}}
\newcommand{\@descr}{}
\newcommand{\descr}[1]{\renewcommand{\itshape \@descr{#1}}}
\newcommand{\@note}{}
\newcommand{\note}[1]{\renewcommand\@note{#1}}
I have the following command defined, which works under the most common use case.
\newcommand{\makenamedentry}{
\ifx\@name\@emptymacro
\else
{\color{black}\sffamily\bfseries \@name}\\ % print the entry name
\vspace{1.5pt plus 0.5pt minus 0.5pt}
\fi
\ifx\@descr\@emptymacro
\else
{\@descr} % print description
\fi
\ifx\@note\@emptymacro
\else
{\@note} % print note
\fi
}
Here is the most common implementation. The key being that it is named.
\name{My Name}
\descr{My Descr}
\note{My Note}
\makenamedentry
I recently tried to use this for a one off case, without a name. It caused the "There's no line here to end" error.
\name{}
\descr{My Descr}
\note{My Note}
\makenamedentry
With some testing I noticed that this however does not have the error. Unfortunately this is an unacceptable solution for me as it is to complicated to explain to those I have useing the end product. So I need to figure out why I am getting the error in the first place.
% used line, either comment or paragraph
\name{}
\descr{My Descr}
\note{My Note}
\makenamedentry
Now I think it has to do with the \\ on line 4 of the newcommand, as that is the only end of line character. What I do not understand is why it is trying to execute under the case when no name is provided. Perhaps the \\ exists outside the normal logic structure? I am not sure.
------------------------------------------------------------------------------------------------------ANSWER BELOW THIS LINE----------------------------
I have edited this post to make the solution more clear.
While the question was about ifx, the reason I was having problems was because my test for emptiness was bad. This was making my code run the \else case (I write all my logic inverted) even when I thought I was not.
The reason being that \name{} was not the samething as \name{null}. Why that is I am not sure, also why \@emptymacro is null when \name{} is not I also cannot say. Regardless my solution was construct \@emptymacro the same way as \@name. For the record I write just about everything inside a .cls file so these commands do work. Something about the @ character breaks them if you take them out as it is a reserved character. If you want to implement them yourself you can simply rename the \@ to \at.
\newcommand{\@emptymacro}{}% Used to test against an empty macro
\newcommand{\emptymacro}[1]{\renewcommand\@emptymacro{#1}}
\emptymacro{}
\newcommand{\@name}{}
\newcommand{\name}[1]{\renewcommand\@name{#1}}
\newcommand{\@note}{}
\newcommand{\note}[1]{\renewcommand\@note{#1}}
\newcommand{\@descr}{}
\newcommand{\descr}[1]{\renewcommand\@descr{#1}}
By having them expand to the same thing this makes me able to test using ifx (which is defined here https://en.wikibooks.org/wiki/TeX/ifx)
\nameand\@emptymacroare defined. – egreg Sep 12 '15 at 22:35{..}around the true or false “arguments”. – Manuel Sep 12 '15 at 22:41\descand\noteare defined. – egreg Sep 12 '15 at 22:43\empty@macrois defined with\defand\@nameis defined with\newcommand(or the other way round) – David Carlisle Sep 12 '15 at 23:02\vspacewill come between the first and second lines of the\descr(or after a one line\descr) is that intended? – David Carlisle Sep 12 '15 at 23:03\nameand\descr. I played with that value to get the spaceing right. – Bob Sep 13 '15 at 02:48\if\relax\detokenize\expandafter{\romannumeral-\Q@name}\relax` – Gonzalo Medina Sep 13 '15 at 04:38\name{}was not the samething as\name{null}. Why that is I am not sure, also why\@emptymacrois null is another question. – Bob Sep 13 '15 at 05:52\newcommand{\name}[1]{\renewcommand{\bfseries \@name{#1}}}is code that cannot possibly work, so it is definitely not part of a complete example. – egreg Sep 13 '15 at 09:08