# why my newcommand reports error?

## 1

\newcommand{\Qf}[3]{\paragraph{$#1$}#2\\#3\\}
...
\Qf[AA][AA][AA]



it says There's no line here to end. \Qf[AA.

## 2

\usepackage{etoolbox}
...
\csdef{Q1}{
1.1.2-1992-2,3-1
}
\csdef{Q1=}{
$f(x)=e^{x^2},f[\varphi(x)]=1-x,\varphi(x) \geqslant 0,\varphi(x),D(\varphi(x))$
}
\csdef{A1}{
$e^{\varphi(x)^2}=1-x \Rightarrow \varphi(x)=\sqrt{\ln (1-x)}\Rightarrow x<1$
}
\newcommand{\toA}[1]{\hyperlink{answer-#1}{answer}\hypertarget{question-#1}{}}
\newcommand{\toQ}[1]{\hyperlink{question-#1}{back}\hypertarget{answer-#1}{}}

\toQ{\csuse{Q1}}
\csuse{Q1=}
\newpage
\toA{\csuse{Q1}}


it says Undefined control sequence. \toQ{\csuse{Q1}} and Undefined control sequence. \toA{\csuse{Q1}}

## 3

\usepackage{etoolbox}
...
\csdef{Q1}{
1.1.2-1992-2,3-1
}
\csdef{Q1=}{
$f(x)=e^{x^2},f[\varphi(x)]=1-x,\varphi(x) \geqslant 0,\varphi(x),D(\varphi(x))$
}
\csdef{A1}{
$e^{\varphi(x)^2}=1-x \Rightarrow \varphi(x)=\sqrt{\ln (1-x)}\Rightarrow x<1$
}
\newcommand{\toA}[1]{\hyperlink{answer-#1}{answer}\hypertarget{question-#1}{}}
\newcommand{\toQ}[1]{\hyperlink{question-#1}{back}\hypertarget{answer-#1}{}}

\Qf[\csuse{Q1}][\toA[\csuse{Q1}]][\csuse{Q1=}]


it says There's no line here to end. \Qf[\csuse{Q1}

I don't know why, really confuse me in different error-info.

• Ad 1) With \newcommand{\Qf}[3]{\paragraph{$#1$}#2\\#3\\} you define a macro that takes three mandatory arguments, but \Qf[AA][AA][AA] looks more like a macro with three optional arguments. The macro should be called with \Qf{AA}{BB}{CC}. This might still not resolve the There's no line here to end. issue, though depending on the exact use case of your macro. We'd need to see a full example document and not just snippets to be able to help here, though. See tex.meta.stackexchange.com/q/228/35864 – moewe Aug 9 '19 at 15:27
• Ad 2) If I load the packages \usepackage{amssymb} and \usepackage{hyperref} I get no error from those lines of code. – moewe Aug 9 '19 at 15:28
• Ad 3) This combines issues from 1 and 2. Mandatory arguments to a macro must be given in curly brackets, not square brackets. So you need \Qf{\csuse{Q1}}{\toA{\csuse{Q1}}}{\csuse{Q1=}}. You also need the packages from 2. – moewe Aug 9 '19 at 15:31
• you are just posting disconnected fragments that makes it hard to test and see the error. Please always post complete small test documents. – David Carlisle Aug 9 '19 at 16:01
• I tried to make the first example into a test file but \documentclass{article} \begin{document} \newcommand{\Qf}[3]{\paragraph{$#1$}#2\\#3\\} \Qf[AA][AA][AA] \end{document} runs without error please make a test file that shows the no line here to end error. – David Carlisle Aug 9 '19 at 16:26

## 1 Answer

It is best to only ask one question per post, and to provide a test file but:

1

\documentclass{article}

\begin{document}

\newcommand{\Qf}[3]{\paragraph{$#1$}#2\\#3\\}

\Qf[AA][AA][AA]

\end{document}


this does not generate the error stated or any error, however the three arguments to \Qf are [, A and A.

\paragraph is a sectioning command with a run-in heading that is inlined into the first sentence of the paragraph, so using display math  in the heading is very weird, and in this case the display just consists of [ with the first two lines from #2 and #3 both being A so you get:

2

You do not say what error you got, nor give a test file.

\documentclass{article}

\usepackage{etoolbox}

\begin{document}
\csdef{Q1}{
1.1.2-1992-2,3-1
}
\csdef{Q1=}{
$f(x)=e^{x^2},f[\varphi(x)]=1-x,\varphi(x) \geqslant 0,\varphi(x),D(\varphi(x))$
}
\csdef{A1}{
$e^{\varphi(x)^2}=1-x \Rightarrow \varphi(x)=\sqrt{\ln (1-x)}\Rightarrow x<1$
}
\newcommand{\toA}[1]{\hyperlink{answer-#1}{answer}\hypertarget{question-#1}{}}
\newcommand{\toQ}[1]{\hyperlink{question-#1}{back}\hypertarget{answer-#1}{}}

\toQ{\csuse{Q1}}
\csuse{Q1=}
\newpage
\toA{\csuse{Q1}}
\end{document}


Produces the error

! Undefined control sequence.
\toQ #1->\hyperlink
{question-#1}{back}\hypertarget {answer-#1}{}
l.20 \toQ{\csuse{Q1}}

?


showing that \hyperlink hyperlink is undefined.

Changing the \usepackage line to

\usepackage{etoolbox,hyperref}


resolves that error, but produces the error:

! Undefined control sequence.
\Q1= ...,f[\varphi (x)]=1-x,\varphi (x) \geqslant
0,\varphi (x),D(\varphi (x...
l.21 \csuse{Q1=}

?


Showing that \geqslant is undefined, so changing the \usepackage line to

\usepackage{etoolbox,amssymb,hyperref}


makes the example run without error.

3

I could not guess how to extend your fragment into an example that gave the stated error.

\documentclass{article}

\usepackage{etoolbox,amssymb,hyperref}

\begin{document}

\newcommand{\Qf}[3]{\paragraph{$#1$}#2\\#3\\}

\csdef{Q1}{
1.1.2-1992-2,3-1
}
\csdef{Q1=}{
$f(x)=e^{x^2},f[\varphi(x)]=1-x,\varphi(x) \geqslant 0,\varphi(x),D(\varphi(x))$
}
\csdef{A1}{
$e^{\varphi(x)^2}=1-x \Rightarrow \varphi(x)=\sqrt{\ln (1-x)}\Rightarrow x<1$
}
\newcommand{\toA}[1]{\hyperlink{answer-#1}{answer}\hypertarget{question-#1}{}}
\newcommand{\toQ}[1]{\hyperlink{question-#1}{back}\hypertarget{answer-#1}{}}

\Qf[\csuse{Q1}][\toA[\csuse{Q1}]][\csuse{Q1=}]
\end{document}


produces the error

! Missing \endcsname inserted.
<to be read again>
\protect
l.24 \Qf[\csuse{Q1}
][\toA[\csuse{Q1}]][\csuse{Q1=}]
?


as here the three arguments of \Qf are [, \csuse and {Q1}

so the #2\\ in the replacement text of \Qf will be \csuse\\ which is taking the command \\ as the argument to \csuse but as this does not expand to a list of characters it can not form a csname and you get the low level \endcsname error shown.

• thank you for your editing.I've solved all the problem.1) \Qf[][][]substitute [] with {} 2), 3) I fogot importing package – nevermind_15 Aug 9 '19 at 23:14