escaping backslash when printing a plot using -dpslatex

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

escaping backslash when printing a plot using -dpslatex

Josua Stingelin
Dear Octave developers,

Thank you very much for your amazing work on GNU Octave! I'm using it for most
tasks the university expects me to do in MATLAB.

I've noticed that printing plots for further use in latex using the '-dpslatex'
option

    print (fig, file, '-pslatex')

requires escaping backslashes in labels

    xlabel ("$t [\\si{ms}]$");

is this expected behavior?

I don't think it's entirely clear from the documentation [1]

> The text that is written to the LaTeX file contains the strings exactly as
> they were specified in the plot. If any special characters of the TeX mode
> interpreter were used, the file must be edited before LaTeX processing.
> Specifically, the special characters must be enclosed with dollar signs ($ …
> $), and other characters that are recognized by LaTeX may also need editing
> (.e.g., braces). The ‘pdflatex’ device, and any of the ‘standalone’ formats,
> are not available with the Gnuplot toolkit.

[1]: https://octave.org/doc/v4.2.0/Printing-and-Saving-Plots.html




signature.asc (499 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: escaping backslash when printing a plot using -dpslatex

Josua Stingelin
On Thu, Apr 02, 2020 at 01:15:12PM +0200, Josua Stingelin wrote:

> Dear Octave developers,
>
> Thank you very much for your amazing work on GNU Octave! I'm using it for most
> tasks the university expects me to do in MATLAB.
>
> I've noticed that printing plots for further use in latex using the '-dpslatex'
> option
>
>     print (fig, file, '-pslatex')
>
> requires escaping backslashes in labels
>
>     xlabel ("$t [\\si{ms}]$");
>
> is this expected behavior?
>
> I don't think it's entirely clear from the documentation [1]
>
> > The text that is written to the LaTeX file contains the strings exactly as
> > they were specified in the plot. If any special characters of the TeX mode
> > interpreter were used, the file must be edited before LaTeX processing.
> > Specifically, the special characters must be enclosed with dollar signs ($ …
> > $), and other characters that are recognized by LaTeX may also need editing
> > (.e.g., braces). The ‘pdflatex’ device, and any of the ‘standalone’ formats,
> > are not available with the Gnuplot toolkit.
>
> [1]: https://octave.org/doc/v4.2.0/Printing-and-Saving-Plots.html
>


Actually string behavior is well documented [2] I was just looking in the wrong
place.

When using double quotes the backslash is used as an escape character and thus
needs to be escaped itself.

When using single quotes one can use the backslash as is. However it is not
recommended to use the single quote because it's also used for the transpose
operator.

[2] https://octave.org/doc/v5.2.0/Strings.html