Tufte-LaTeX / tufte-latex

A Tufte-inspired LaTeX class for producing handouts, papers, and books
https://tufte-latex.github.io/tufte-latex/
1.68k stars 300 forks source link

gnuplottex is broken with tufte #140

Closed ernestum closed 5 years ago

ernestum commented 5 years ago

I am trying to include a gnuplot plot using gnuplottex like this

\begin{figure}
    \centering
    \begin{gnuplot}[terminal=cairolatex,scale=1]
        set style line 1 lt 2 lc rgb "black" lw 7 dt 1
        set style line 2 lt 2 lc rgb "gray50" lw 7 dt 2
        set style line 3 lt 2 lc rgb "gray70" lw 3 dt 1
        set size .6,.6

        set samples 400
        set border 1 behind ls 3
        set key right center invert reverse
        set xrange[0:1]

        set ylabel "propeller speed"

        offset = 0.2
        set xtics ('$t$' offset, '$t+\Delta$' 0.8) nomirror out
        set ytics ('$\omega_t$' 0, '$\omega_{t+\Delta}$' 1) scale 0
        t(x) = x > offset ? 1 : 0
        w(w0, u, iw, t) =  w0 - (iw**t - 1) * (u - w0)

        plot w(0, 1, 0.0001, x-offset) * t(x) w l t '$\omega$' ls 1, \
             t(x) w l t '$u$' ls 2

    \end{gnuplot}
    \caption{Motor step response.}
\end{figure}

When I do that in a normal article, it looks fine like this: image As soon as I enter the same code in my tufte book class, the labels are off: image I guess gnuplotlatex does not like to be placed in an lrbox? Is there anything I could do here?

ernestum commented 5 years ago

Hmm. I think the issue should be somewhere in the definition of @tufte@float but my latex skills are too poor to figure it out right now.

ernestum commented 5 years ago

Ugly ad-hoc solution for anyone that is stuck on the same problem:

  1. Put your gnuplot code in a separate file
  2. Add those lines at the beginning:
    set terminal cairolatex standalone color colortext
    set output '<some_filename_you_like>.tex'
  3. Execute
    gnuplot <your_gnuplot_file>
    pdflatex '<some_filename_you_like>.tex
  4. Include resulting .pdf in your latex file using \includegraphics.
ernestum commented 5 years ago

There is an issue when using the default width for included figures. Do not use

\setkeys{Gin}{width=\linewidth}

So it is an issue with the gnuplot cairolatex terminal.