In LaTeX, one can declare functions in documents using the \newcommand or \newenvironment commands. Here's how one can define a simple function and an environment.
\newcommand{\myfunction}[2]{Function: #1 + #2}
In this example, \newcommand{\myfunction}[2] defines a new command called \myfunction that takes two arguments, that one can use in a document like this:
The function output is: $\myfunction{a}{b}$
Can one make a function like in other languages directly ? For instance, make something like the following.
\feuds_newteorema_simple:nn
{
\newtheorem{#1_inner}
{\color{\feuds_teorema_setcolor_tl}#2}
}
I do get confused when writing all this. Would one enclose with {} when writing commands on the same line ?
Where con I find the declaration for \newtheorem ?
\feuds_newteorema_simple:nn {definition}to define\feuds_newteorema_simple:nn. The code you've given would try to use\feuds_newteorema_simple:nn, so it would look for a definition of that function to feed the next two arguments. If the function doesn't exist, you'd get an error. If it does, you'd get a different error because you've only given one argument and it expects two. – cfr Sep 29 '23 at 19:28\feuds_newteorema_simple:nnto\cs_new_protected:Npn\feuds_newteorema_simple:nn#1#2and then that fragment defines the command. – David Carlisle Sep 29 '23 at 19:29newtheoremhas a definition in the latex format but several packages redefine it:amsthm,ntheorem, ... so where it is documented depends on which version you are using. – David Carlisle Sep 29 '23 at 19:32\def\myfunction#1#2{Function: #1 + #2}– John Kormylo Sep 29 '23 at 19:42amsthmetc. – Veak Sep 29 '23 at 20:01\cs_new_protected:Npnis just to assign the protected mark rather than the defining the function. The definition of the function is\feuds_newteorema_simple. How would a function definition look like when not using the protected mark ? – Veak Sep 29 '23 at 20:29\cs_new_protected:Npndefines a new function (which is protected and can absorb arguments which include paragraph breaks). If you don't want it to be protected, use\cs_new:Npn(allowing paragraph breaks). Then thepmeans you're going to specify the parameters explicitly, rather than having them inferred from the argument specification in the name. – cfr Sep 29 '23 at 20:34\usepackage{amsthm}, you're using the definition fromamsthm(unless something later redefines the command again). You can also say\show\newtheoremto be shown the current definition on the terminal during compilation of the document. (However, this isn't always helpful if the command is protected, for example.) – cfr Sep 29 '23 at 20:36\cs_newto define a function. – Veak Sep 29 '23 at 20:42\cs_newwill give an error because it is not the name of a function if you omit the colon and signature. – cfr Sep 29 '23 at 20:49