manpagez: man pages & more
info gnuplot
Home | html | info | man
[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1.21.2 Substitution of string variables as macros

Substitution of command line macros is disabled by default, but may be enabled using the macros command. If macro substitution is enabled, the character @ is used to trigger substitution of the current value of a string variable into the command line. The text in the string variable may contain any number of lexical elements. This allows string variables to be used as command line macros. Only string constants may be expanded using this mechanism, not string-valued expressions. For example:

 
      set macros
      style1 = "lines lt 4 lw 2"
      style2 = "points lt 3 pt 5 ps 2"
      range1 = "using 1:3"
      range2 = "using 1:5"
      plot "foo" @range1 with @style1, "bar" @range2 with @style2

The line containing @ symbols is expanded on input, so that by the time it is executed the effect is identical to having typed in full

 
      plot "foo" using 1:3 with lines lt 4 lw 2, \
           "bar" using 1:5 with points lt 3 pt 5 ps 2

The function exists() may be useful in connection with macro evaluation. The following example checks that C can safely be expanded as the name of a user-defined variable:

 
      C = "pi"
      if (exists(C)) print C," = ", @C

Macro expansion does not occur inside either single or double quotes. However macro expansion does occur inside backquotes.

For execution of complete commands the evaluate command may also be handy.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]
© manpagez.com 2000-2024
Individual documents may contain additional copyright information.