1

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)

closed as unclear what you're asking by egreg, Mensch, Heiko Oberdiek, user13907, Martin Schröder Sep 13 '15 at 10:05

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    Please, make a complete compilable example. In particular it's important to know how \name and \@emptymacro are defined. – egreg Sep 12 '15 at 22:35
  • No need for {..} around the true or false “arguments”. – Manuel Sep 12 '15 at 22:41
  • 1
    @Manuel It depends on how \desc and \note are defined. – egreg Sep 12 '15 at 22:43
  • I have some suspects, but without a complete example, it's just guessing. – egreg Sep 12 '15 at 22:44
  • 1
    @Bob I asked for a complete example for a reason. You don't want to show it: of course \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 9:08
1

The \ifx is working in your code. If you don't provide the MWE where the error occurs than we cannot guessing anything.

But your code includes many LaTeX misunderstandings. I rewrite your result to TeX primitives in order to more clear understand what happened.

(1) When name is nonempty, then the result is:

\indent NAME\hfil\break
\vadjust{\vskip1.5 pt plus.5pt minus.5pt}\space DESCRIPTION \par

\indent NOTE

The \hfil\break ends the first line of the paragraph where NAME is (this is roughly speaking the expansion of \\ macro). The second line of paragraph starts with \vadjust (this is roughly speaking the expansion of \vspace macro). The \vadjust command puts the space after the second line of paragraph, it means between first and second line of DESCRIPTION. If the DESCRIPTION is only one line long then vertical space will be after the paragraph. The paragraph is ended at the end of DESCRIPTION (TeX inserts \par at the empty line in your code). Finally new paragraph starts with NOTE.

Note that if you have \parindent nonzero, then you get indentation before NAME and NOTE, but no indentation before DESCRIPTION. Only one space is before DESCRIPTION (it comes from the end of your line where \vspace is used).

Note that the second paragraph is not finalized. It means that if you type

\makenamedentry 
something more` 

then the text something more will be appended to the second paragraph at the same line where the NOTE is.

(2) When the NAME is empty then you get:

\indent DESCRIPTION\par

\indent NOTE

Simple two paragraphs are here. But the second paragraph is not ended, of course.

I guess that you needs something like this:

\newtoks\name \newtoks\descr \newtoks\note
\def\makenamedentry{\par
    {\bf \the\name}\par
    \ifx^\the\name^\else \vskip 1.5pt plus.5pt minus.5pt \fi
    \the\descr\par
    \the\note\par
}

\name{My Name}
\descr{This is a description}
\note{some note}
\makenamedentry
  • When I post questions I always try to trim down the parts in order to make it focus only on the parts I have questions about. In this case I have accidentally solved my issue in making it simpler. I have edited my initial post to show a change on the variable declaration. Notice how name turns the characters bold. I have found my issue, here is a working example overleaf.com/3240936mmngtz. – Bob Sep 13 '15 at 6:54
  • Although my vspace seems to work fine. Wouldnt \name and \descr be the same paragraph? Making \descr the second line? – Bob Sep 13 '15 at 6:57

Not the answer you're looking for? Browse other questions tagged or ask your own question.