next up previous
Next: More Advanced Uses of Up: Advanced Features Previous: Coordinates and Dimensions

More about C

An ePiX input file is really source code for a C program that writes an .eepic file as output. If you do not speak C, the main things to remember (principally differences between LATEX and C syntaxes) are:

  1. Comments, which may span several lines, are delimited by the strings /* and */. One-line comments, similar to LATEX comments, are begun with // (analogous to the LATEX %) and end with the next newline. A //-style comment may appear within a multiline comment, but a /* */ comment may not; the C compiler will mistake the first */ it encounters as the end of the current multiline comment.

  2. Every statement and function call must end with a semicolon. If you omit a semicolon, the compiler will give you a cryptic error message (such as `parse error at line N' if the semicolon is missing on the last non-blank line before line N).

    Lines that begin with #include or #define are C pre-processor directives, and do not end with a semicolon.

  3. As in LATEX , the backslash \ is an escape character in C. To print a \ from C, you must use \\, as in
    
      /* Put label $y=\sin x$ at (2,1) */
      /* Note single  ^ backslash in output */
      label(P(2,1), P(0,0), "$y=\\sin x$"); 
      /*       Double backslash ^^ in source */
    

  4. Variables in C must have a declared type, such as int (integer), double (double-precision floating point), or char (string of characters), and should be defined in the preamble or at the beginning of main. (Variables local to a function must be defined at the beginning of the function.) Variable and function names may contain letters (including underscore) and digits, are case sensitive, and must begin with a letter.

  5. C requires explicit use of * to denote multiplication; simple juxtaposition is not enough. C does not support the use of ^ for exponentiation, e.g., t^2 is invalid. Instead, you must use t*t or pow(t,2).

  6. The following words are reserved in C, and may not be used as function or variable names:

    auto double int struct
    break else long switch
    case enum register typedef
    char extern return union
    const float short unsigned
    continue for signed void
    default goto sizeof volatile
    do if static while

    In addition, ePiX reserves the following variables:

    x_min x_max y_min y_max
    h_size v_size h_offset v_offset
    x_size y_size pic_size pic_unit

    C is case-sensitive, so capitalized variants are valid (but discouraged).

The aspect ratio of the figure is controlled by adjusting the LATEX size of the figure and its Cartesian bounding box. The following length units may be used: cm, in, mm, pc, and pt. (One pica equals 12 pt.) Font-dependent units em and ex, and ``exotic'' units (Didot points, Ciceros, etc.) are not recognized. See lengths.cc to add support for other length units.

Aside from #include and #define statements, and variable declarations, the preamble consists of function definitions, for plotting functions you have specified. Functions may not be defined inside other functions; in particular, all definitions of user-specified functions must come in the preamble, before the call to main.

C knows the following functions of one variable by name:

sqrt sin sinh asin
ceil cos cosh acos
floor tan tanh atan
exp log log10 fabs (abs val)
The inverse trig functions are principle branches. In addition, pow(x,y) returns $ x^y$ when real, and atan2(y,x) returns $ {\rm Arg}(x+iy)$, the principle branch of arg. C knows many constants to 20 decimal places (such as M_PI, M_PI_2, and M_E for $ \pi$, $ \pi/2$, and $ e$ respectively; there are over a dozen in all). ePiX defines a few additional functions, such as recip (the reciprocal, defined to be 0 at 0) and cb (for ``Charlie Brown''), the period-2 extension of the absolute value function on $ [-1,1]$. If you use certain functions frequently, add them to functions.cc and recompile ePiX.

The GNU C library defines many other functions, including inverse hyperbolic functions, log and exp with base 2, 10, or arbitrary $ b$, the error and gamma functions, and Bessel functions of first and second kind.

You may use known functions in subsequent definitions. Functions of two (or more) variables are defined in direct analogy to functions of one variable:


double f(double t)
{
  return t*t*log(t*t); // t^2 \ln(t^2)
}

double g(double s, double t)
{
  return exp(2*s)*cosh(sin(M_PI*t));
}


next up previous
Next: More Advanced Uses of Up: Advanced Features Previous: Coordinates and Dimensions
hwang
2002-06-06