is a MathLink template file.


  • MathLink template files contain templates for linking external C functions to Mathematica functions.
  • Each template can contain the following:
  • :Begin:begin the template for a particular function
    :Function:the name of the function in the external program
    :Pattern:the pattern to be defined to call the function
    :Arguments:the arguments to the function
    :ArgumentTypes:the types of the arguments to the function
    :ReturnType:the type of value returned from the function
    :End:end the template
    :Evaluate:Mathematica input to evaluate when the function is installed
    ::texttreat as a comment
  • Arbitrary C code can be interspersed between templates in a .tm file.
  • The following argument and return type specifications can be used:
  • Integer16short
    Integer16Listshort*, int (length)
    Integer32Listint*, int (length)
    Integer64Listmlint64*, int (length)
    Real32Listfloat*, int (length)
    Real64Listdouble*, int (length)
    Real128Listmlextended_double*, int (length)
    ByteStringunsigned char* and int (length)
    UCS2Stringunsigned short*
    UTF8Stringunsigned char*, int (bytes), int (characters)
    UTF16Stringunsigned short*, int (length), int (characters)
    UTF32Stringunsigned int*, and int (length)
    ByteSymbolunsigned char*, int (length)
    UCS2Symbolunsigned short*, int (length)
    UTF8Symbolunsigned char*, int (bytes), int (characters)
    UTF16Symbolunsigned short*, int (length), int (characters)
    UTF32Symbolunsigned int*, int (length)
  • MathLink template files are converted to C code using mprep. They are also processed automatically by mcc when available.

ExamplesExamplesopen allclose all

Basic Examples (1)Basic Examples (1)

Template file entry for a function named that takes two integers as arguments and returns an integer:

:Function:        f
:Pattern:        f[x_Integer, y_Integer]
:Arguments:        {x, y}
:ArgumentTypes:    {Integer, Integer}
:ReturnType:    Integer
New to Mathematica? Find your learning path »
Have a question? Ask support »