juliapgfplots

Syntax for including the value of a declared variable inside a node in PGFPlots annotation?


In Julia, I have declared a variable, say, x = 3.5. Now I want to include this variable inside some annotation of a plot using PGFPlotsX.

x = 3.5

using PGFPlotsX
@pgf Axis(
         plot(
             Table(
             ),
         ),
          raw"node[anchor = south west] at (.3,.3){$x = <variable name i.e., x >$}"
     ) 

What should be the appropriate syntax within the $$ inside the node? I want to avoid hard-coding the value, 3.5, of x inside the node.


Solution

  • Your problem is that you want to interpolate inside a String when you are using the @raw_str macro which is defined as:

    help?> @raw_str
      @raw_str -> String
    
      Create a raw string without interpolation and unescaping. (...)
    

    So what you can do is either to not use raw" but then you need to escape $:

    "node[anchor = south west] at (.3,.3){\$x = $x >\$}"
    

    This will nicely interpolate x.

    The second option is to concatenate Strings:

     string(raw"node[anchor = south west] at (.3,.3){$x = ", x, raw"  = $x >$}")