I noob in LaTeX3 and I try to understand this language.
As I read here one can define a new macro by using \cs_new:
\cs_new:Npn \SayHello #1
{ \prg_replicate:nn {#1} { Hello~World!~ } }
where N respect to \SayHello, p --- to #1 and n --- to {...}
Ok, I try to create my function to show square of some number:
\cs_new:Npn \Show #1
{
\int_eval:n {#1*#1}
}
Macro \Show{number} work fine.
But if I try to define macro \Show, which should show me some integer:
\cs_new:Nn \Show
{
\int_eval:n {2+2}
}
I get a LaTeX error: "kernel/missing-colon".
Ok, then I add a colon:
\cs_new:Nn \Show:n
{
\int_eval:n {2+2}
}
and I agein get an error, but now it just ! Undefined control sequence.
This behavior is not clear to me. Where am I breaking the rules?
MWE below.
\documentclass{article}
\usepackage{expl3}
\ExplSyntaxOn
\cs_new:Nn \Show:n
{
\int_eval:n {2+2}
}
\ExplSyntaxOff
\begin{document}
\Show{}
\end{document}
pallow for non - colon macro names, the other ones must have a colon at the end! You can't call\Showjust this way outside ofexpl3space. You must define it withNpnor call it with\Show:n{}in expl3 space – Jan 28 '17 at 17:46\Show:to work with\cs_new:Nn, or if you use\cs_new:Npnyou can use whatever name you want. In any case, you should actually define\Showwithxparseto make the public interface, and then the internal throughexpl3language. Of course, for this example is too much, but in general that should be the way. – Manuel Jan 28 '17 at 17:52\cs_new:Npn \sergio_show: {...}(without argument) or\cs_new:Npn \sergio_show:n #1 {...}(with argument) and define the document command in addition (withxparse):\NewDocumentCommand \Show {} { \sergio_show: }or\NewDocumentCommand \Show {m} { \sergio_show:n {#1} }– cgnieder Jan 28 '17 at 18:08xparse, why notLaTeX3directly? In the first example it was possible. – sergiokapone Jan 28 '17 at 18:15\<module>_<name>:<arg spec>). – cgnieder Jan 28 '17 at 18:21