FUNCTION: Difference between revisions
No edit summary |
No edit summary |
||
(3 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
{{Keyword | {{Keyword | ||
| | |1= | ||
<code>FUNCTION { hints, [[symbol]], [[symbol]]|[[ | <code>FUNCTION { { hints }, [[symbol]], [[symbol]]|[[symbol list]] }</code> | ||
| | |||
Declare a user-defined function. | <code>FUNCTION { { hints }, [[string]], [[symbol]], [[symbol]]|[[symbol list]] }</code> | ||
|2= | |||
Declare a user-defined function. In the first form, the second parameter is the name of the function and the the third parameter declares the arguments of the function and can be either a single symbol or a list of symbols. | |||
In the second form, the second parameter is an optional print name for the function. This makes it possible to define multiple functions that print with the same name. This is mostly useful if you want a function that takes a [[quantity|quantities]] as its argument. | |||
The way that iMath treats this function can be influenced by function hints: | The way that iMath treats this function can be influenced by function hints: | ||
* none: No function hints. Must be used because iMath requires three arguments to the <code>FUNCTION</code> declaration. | * none: No function hints. Must be used because iMath requires three arguments to the <code>FUNCTION</code> declaration. | ||
* lib: A | * lib: A library function. It will not be affected by <code>[[CLEAREQUATIONS]]</code>. This is useful for building up a collection of functions that can be used throughout the whole document. | ||
* trig: For trigonometric functions. Tells iMath that this function will get special treatment when printing (e.g. sin²''x'' instead of (sin''x'')²) . | * trig: For trigonometric functions. Tells iMath that this function will get special treatment when printing (e.g. sin²''x'' instead of (sin''x'')²) . | ||
* expand: The function is to be expanded immediately. Useful for functions that are abbreviations, e.g. <code>square(x)</code> will be expanded to <code>x^2</code> whenever it is used. | * expand: The function is to be expanded immediately. Useful for functions that are abbreviations, e.g. <code>square(x)</code> will be expanded to <code>x^2</code> whenever it is used. | ||
Line 13: | Line 16: | ||
* defdiff: Differentiate the definition of the function, not the function itself (e.g. <code>sin(x)</code> will be differentiated to <code>cos(x)</code> and not to <code>(sin(x))'</code>. | * defdiff: Differentiate the definition of the function, not the function itself (e.g. <code>sin(x)</code> will be differentiated to <code>cos(x)</code> and not to <code>(sin(x))'</code>. | ||
| | | | ||
<code>FUNCTION {none, f, x}</code> declares the function <code>f</code> with one argument. | 3= | ||
| | <code>FUNCTION { {none}, f, x}</code> declares the function <code>f</code> with one argument. | ||
<code> | |||
FUNCTION { {none}, "cos", rcos, x} | |||
FUNCDEF rcos(x) = cos(x / %unity) | |||
</code> | |||
declares a variant of the cosine function that can handle arguments with the unit <code>%unity</code>. Have a look at the [[FAQ#Using_iMath_questions|FAQ entry]] "How can I have iMath print the unit <code>%radian</code>?". | |||
|4= | |||
[[FUNCDEF]] | [[FUNCDEF]] | ||
|5= | |||
2.2.0 or earlier (the second form exists since 2.2.4) | |||
}} | }} | ||
[[Category:Declaration]] | [[Category:Declaration]] |
Latest revision as of 19:53, 27 June 2018
Syntax
FUNCTION { { hints }, symbol, symbol|symbol list }
FUNCTION { { hints }, string, symbol, symbol|symbol list }
Implemented in iMath since version 2.2.0 or earlier (the second form exists since 2.2.4).
Explanation
Declare a user-defined function. In the first form, the second parameter is the name of the function and the the third parameter declares the arguments of the function and can be either a single symbol or a list of symbols. In the second form, the second parameter is an optional print name for the function. This makes it possible to define multiple functions that print with the same name. This is mostly useful if you want a function that takes a quantities as its argument.
The way that iMath treats this function can be influenced by function hints:
- none: No function hints. Must be used because iMath requires three arguments to the
FUNCTION
declaration. - lib: A library function. It will not be affected by
CLEAREQUATIONS
. This is useful for building up a collection of functions that can be used throughout the whole document. - trig: For trigonometric functions. Tells iMath that this function will get special treatment when printing (e.g. sin²x instead of (sinx)²) .
- expand: The function is to be expanded immediately. Useful for functions that are abbreviations, e.g.
square(x)
will be expanded tox^2
whenever it is used. - nobracket: The function does not require brackets around the argument (e.g.
sqrt(x)
is printed as <math>root x</math>). - defdiff: Differentiate the definition of the function, not the function itself (e.g.
sin(x)
will be differentiated tocos(x)
and not to(sin(x))'
.
Example
FUNCTION { {none}, f, x}
declares the function f
with one argument.
FUNCTION { {none}, "cos", rcos, x}
FUNCDEF rcos(x) = cos(x / %unity)
declares a variant of the cosine function that can handle arguments with the unit %unity
. Have a look at the FAQ entry "How can I have iMath print the unit %radian
?".