larskotthoff / gnuplottex

Gnuplot graphs in LaTeX. See http://www.ctan.org/pkg/gnuplottex
3 stars 1 forks source link

Output to file only? +specify name? #13

Open gobbedy opened 4 years ago

gobbedy commented 4 years ago

Hello,

First of all thank you for this wonderful package. It's such a relief that I don't have to write my gnuplot code separately from my latex.

I notice with terminal=pdf, a pdf file is generated. Is it possible to get gnuplottex to only generate a pdf file, which I can later include using \includegraphics?

In that same vein, is it possible to specify a filename for the generated pdf?

Thanks in advance.

larskotthoff commented 4 years ago

This is what gnuplottex does internally. If you want to explicitly include a generated PDF, I would recommend generating it separately. Does that answer your question, or am I misunderstanding what you want to do?

gobbedy commented 4 years ago

Hi Lars,

Thank you for your fast response. Yes, you understood correctly.

Unfortunately, generating separately is what I'm trying to avoid because I'm including the generated curve in a tikz picture, and then doing lots of tikz drawing overtop the gnuplot graph. I do many small changes to the gnuplot, which require many counterpart changes to the tikz drawings.

Generating separately, then updating the tikz diagram, then updating the gnuplot, and so on, in an iterative fashion, is exactly what I am trying to avoid by using gnuplottex. Indeed, I want to be able to stay inside latex to work more efficiently.

I did find a solution, but it is hackish and not cross-platform (it involves making system calls which are OS specific). It also involves hardcoding the name of the generated file. Below is a standalone to demonstrate what I've done. Note that it only works on Windows due to the system call.

\documentclass[14pt]{extarticle}
\usepackage{pgfplots}
\usepackage[miktex]{gnuplottex}

\begin{document} 
    \begin{gnuplot}[terminal=tikz]
        #set term push
        set xrange [ 0.00000 : 1.00000 ] noreverse nowriteback;
        set yrange [ 0.00000 : 2.00000 ] noreverse nowriteback;
        Binv(p,q)=exp(lgamma(p+q)-lgamma(p)-lgamma(q));
        beta(x,p,q)=p<=0||q<=0?1/0:x<0||x>1?0.0:Binv(p,q)*x**(p-1.0)*(1.0-x)**(q-1.0);

        #set linetype 1 lc rgb '#A3001E'

        set style fill transparent solid 0.35 noborder
        unset border
        unset xtics
        unset ytics

        filter(x,min,max) = (x > min && x < max) ? x : 1/0

        # very hackish gnuplot code to get relative path to 'figures' directory and create filename string
        # assumes that working directory is parent directory of 'uottawa-thesis.tex', and that this dir contains a 'figures' dir
        # ASSUMES THAT OS IS WINDOWS; on mac/linux, replacing "echo '%cd%'" with "echo \'$PWD\'" would probably work
        filename=`echo '%cd%'`.'\beta_3_3_pdf.png'

        set output filename
        set terminal png size 400,400
        #plot sin(x)
        plot '+' using (filter($1, 0.0, 0.8)):(beta($1, 3.0, 3.0)) with filledcurves x1 fs pattern 4 lc rgb "blue" notitle,\
        ''  using (filter($1, 0.8, 1.0)):(beta($1, 3.0, 3.0)) with filledcurves x1 fs pattern 5 lc rgb "green" lt 1 notitle,\
        '' using 1:(beta($1, 3.0, 3.0)) with lines lw 3 lc rgb '#000099' notitle
        #set term pop
        #plot sin(x)
    \end{gnuplot}

    \begin{figure}[ht!]
        \centering
        \begin{tikzpicture}[scale=1.6]
        \node[anchor=south west,inner sep=0] (image) at (-0.17,-0.21) {\includegraphics[scale=0.67]{beta_3_3_pdf.png}};
        \draw[->] (0,0) -- (5,0) node[right] {\small $\lambda$};
        \draw[->] (0,0) -- (0,4.5) node[above] {\small $f(\lambda)$};
        \draw[dashed] (2,0) -- (2,4) node[above] {};
        \node[] at (2, -0.2){\small $\lambda=0.5$};
        \node[] at (3.2, -0.1){\tiny $\lambda=\lambda_0$};
        \end{tikzpicture}
        \caption{Example of PDF function where $f(\lambda)=f(1-\lambda)$}
        \label{fig:cdf_symmetry}
    \end{figure}

\end{document}
gobbedy commented 4 years ago

So this github issue amounts to a feature suggestion: an argument to gnuplottex which allows specifying the name of the generated pdf, to be used with terminal=pdf. Ah, and the ability to generate only the pdf file (no latex typesetting output). =)

larskotthoff commented 4 years ago

Ok, I have no plans to support this, but pull requests welcome :)

I don't know what you mean by the second suggestion. Generate only the gnuplot PDF without typesetting the document? That's not possible...

gobbedy commented 4 years ago

Ok, no problem. Your project is great, thank you for this initiative it has helped me greatly. And this is definitely not worth implementing if there are very few users that want it (let alone, just me -- and I already have a workaround).

What I mean by my suggestion is that in my use case, I want the gnu plot to be outputted only to the PDF file, not in the document itself. I include the PDF later, so I don't want the plot to appear in the latex document when first generated. I think I used the word typesetting incorrectly, so ignore my initial wording of that suggestion.

larskotthoff commented 4 years ago

Ah ok -- in that case I would suggest to simply run gnuplot separately. You could create a script that does this and runs latex as well to compile the document. I don't want gnuplottex to become a general build system for gnuplot graphs though as this would take it too far beyond its current scope.

gobbedy commented 4 years ago

I'm writing my thesis in latex and I need many of the latex editing features provided by texstudio, including the ability to build and view my work. Creating a script that runs latex is not realistic in my case, as it would not allow me to control generation of my thesis pdf from within texstudio.

I understand that in many cases doing separate work is better way to do things; and that really depends on where the overwhelming volume of the work resides, and in general on the user's workflow. In my case, I have thousands of lines of latex code and it's more efficient to create a gnuplot from within latex.

Perhaps my use case is very narrow and not applicable to most users, but this really is best for my workflow. Another solution -- again not ideal for me -- would be to create a separate script that generates the gnuplot, called from within latex. But again, that would require me maintaining a script outside of the texstudio environment, which would hinder my iterative workflow. Seeing the gnuplot code inside texstudio is really helpful for me.

In any case, I'm satisfied with the workaround. gnuplottex has definitely helped, even if it wasn't your intended use case :)

gobbedy commented 4 years ago

Btw, another reason that maintaining outside scripts is not realistic for me is that I need to share my latex code with others. Everything needs to be self-contained in latex because that's what academics expect to receive and run.

larskotthoff commented 4 years ago

In that case I would really recommend making the figures using tikz or similar ;)

gobbedy commented 4 years ago

That was my first thought. But try plotting the CDF of a beta distribution in tikz :) There is a vast library of online knowledge for plotting complex math functions via gnuplot. Not so much for tikz. I'm sure it would be possible, but again the question is efficiency.

uhoefel commented 4 years ago

This sounds to me like you want to use the gnuplot environment inside a tikzpicture and use the externalize command from tikz. I have done that for a long time, and it works quite nicely. Example:\tikzsetnextfilename{FeAcetonH2O955LaserPowerMH20K}\begin{tikzpicture}[gnuplot]    \begin{gnuplot}[terminal=tikz, terminaloptions={color nopicenvironment scale 0.6,0.6}]# your gnuplot code    \end{gnuplot}     % your tikz code \end{tikzpicture}Best,Udo

Am Dienstag, 14. Januar 2020, 00:50:08 MEZ hat gobbedy <notifications@github.com> Folgendes geschrieben:  

That was my first thought. But try plotting the CDF of a beta distribution in tikz :) There is a vast library of online knowledge for plotting complex math functions via gnuplot. Not so much for tikz. I'm sure it would be possible, but again the question is efficiency.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe.