As written in the title, I am trying to create a multipage pdf with gnuplots cairolatex terminal.
I am using gnuplot 5.4 in cygwin.
Single page works fine, i.e.
./gnuplot-script
pdflatex plot.tex
However when I plot multiple pages in the gnuplot-script, the output .tex file seems to contain errors ..
E.g. the gnuplot-script
set terminal cairolatex standalone
set output "plot.tex"
plot x
plot x**2
outputs a plot.tex that contains two \documentclass{minimal} and pdflatex then complains with
! LaTeX Error: Can be used only in preamble.
...
l.181 \documentclass
{minimal}
I can workaround this by putting each plot into a new file, but it seems a bit strange that simple multipage output is bugged in this terminal?
Am I missing some special command to start a new page in the cairolatex terminal or something? I don't see anything in the documentation for this ..
If you really need to create a TeX-based multipage pdf file directly from gnuplot, I suggest to use the tikz terminal rather than cairolatex.
set terminal tikz standalone
set output "plot.tex"
plot x
plot x**2
unset output
!pdflatex plot
Related
LaTeX is pretty common tool for typsetting symbols and formulas (i.e. \alpha, \frac) and I have learned that there are different terminals that support it, of which I especially like tikz which I often use in LaTeX. However those terminals have output as a file only. Is there any terminal or other option that allows using LaTeX commands and still shows the result instantly in a separate window?
Here is what I would do, and have done on occasion. The refresh does not happen "instantly" since pdflatex is far from instantaneous. However it does have the advantage of keeping you inside the gnuplot session as you work on your figure.
# Create a pdf file holding the initial plot
MYFIGURE = "myfigure.tex"
set term tikz standalone
set output MYFIGURE gnuplot> replot; unset out; system("pdflatex myfigure"); set out MYFIGURE
gnuplot> ... tweak the title, layout, colors, whatever
gnuplot> history !replot
plot PLOT1
unset output
# Display the pdf on the screen using whatever the standard pdf viewer
# is on your system. For me (KDE desktop) this is okular.
system("pdflatex myfigure")
system("okular myfigure.pdf &")
# Draw new or updated versions of the figure into the same file
# okular will notice that the file has changed and refresh the display
set out MYFIGURE
set title "Same figure, new title"
replot
unset out; system("pdflatex myfigure")
set out MYFIGURE
set title "Different figure entirely"
splot FOO with pm3d
unset out; system("pdflatex myfigure")
# ... and so on
If you are continually tweaking the layout of the same figure so that the sequence always involves a replot, then putting the sequence on a single line gnuplot command allows you to re-execute in a singe step using gnuplot's history commands or hitting up-arrow a few times to retrieve the command.
For example:
gnuplot> replot; unset out; system("pdflatex myfigure"); set out MYFIGURE
gnuplot> ... tweak the title, layout, colors, whatever ...
gnuplot> history !replot
gnuplot> ... tweak the figure some more ...
gnuplot> history !replot
Note: TeX will want to find the gnuplot support packages in its normal search path. If they are not already present in your TeX installation, you can follow the instructions in the gnuplot source .../term/lua/README (copied here)
Generating style and help file
==============================
To generate the style files and wrapper for the various TeX flavors enter
lua gnuplot-tikz.lua style
on the command line. The files generated should be
t-gnuplot-lua-tikz.tex (Context wrapper)
gnuplot-lua-tikz.tex (plain TeX wrapper)
gnuplot-lua-tikz.sty (LaTeX wrapper)
gnuplot-lua-tikz-common.tex (common definitions)
and can be copied to the appropriate places.
So I have to write my lab report in Italian for my lab class. In class they taught us how to use gnuplot to create graphs, so I'm using it to produce our graphs, which then I need to put in my latex document. The problem is that I have to set the label on the y axes as "velocità", and when I then save the file in ps and convert in pdf the 'à' disappears or is substituted by something else. What I've tried doing is using variations of the commands
set encoding iso_8859_1
set ylabel "velocit\340"
then I saved the plot using set term postscript color, set output "graf.ps", replot, and from the wsl terminal, using ps2pdf, I converted it into a pdf, but when I open the pdf, the letter 'à' doesn't appear anymore, even though it did show in graph previously generated by gnuplot. What should I do? In case, is there another way I can attach the original graph in my latex document?
Gnuplot provides several LaTeX-friendly terminal types. Postscript is not one of them. Postscript's character encodings are idiosyncratic at best. If your goal is to include gnuplot output in latex, then choose a terminal type that is designed for it. Some terminal types (e.g. cairolatex) work only with latex because they depend on latex to do all the text processing. Others (e.g. pdf, png, tikz) produce output that is fully compatible with latex but already has the text embedded in it. It is best to use UTF-8 encoding for everything, including your accented characters. For example:
set term pdf size 7cm,5cm
set output 'myfigure.pdf'
set encoding utf8
set ylabel "velocità"
set xlabel "tempo"
plot [0:10] x**2 title "velocità"
Then in your latex document, something like:
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
...
My TeX document.
\begin{figure}[h]
\includegraphics{myfigure}
\end{figure}
...
I am working on a .md file which includes latex. The file looks like this:
$$
1+1 = 2
\\
2+2 = 4
$$
The File:
When viewing it as markdown the file looks perfectly fine with the new line properly added.
Although when I use pandoc to write the file to a pdf the following happens:
PDF File (from pandoc)
As you can see the new line has been completely removed and makes the latex hard to read.
I am using the following pandoc command:
pandoc --wrap=preserve in.md -o out.pdf
The --wrap=preserve does not seem to be working as it ignores a new line. I have also tried to use \newline \linebreak instead of \\ and neither seem to be working.
How can I specify a line break so pandoc will make sure to keep the breaks rather than keeping everything inline?
Whatever file preview tool you are using: it is lying to you. Double-backslash is not the correct way to insert newlines into math.
Pandoc either parses the math and converts it into the target format, or just passes the code through, depending on the output format. For PDF output via LaTeX, the equation is just passed through. (You can check by running pandoc with --verbose, which, among other things, will print the generated raw LaTeX code.) So it is clear that the problem lies with the input.
There are multiple ways to add linebreaks into math in LaTeX. One of them is the align* environment:
\begin{align*}
1+1 = 2
\\
2+2 = 4
\end{align*}
This will give you the expected PDF output, but has the downside of not showing up in other output formats like HTML. I'm not aware of any method which would produce linebreaks in math equations across all possible pandoc output formats. You'll have to use multiple single-line equations if you need that.
I am using win7 and octave 3.6.4,
when i generate a plot with octave and save as .eps its colors go away.
For example :
clf();
surf(peaks);
generates following graphic
But when i run the following codes seperately
saveas (1,"test.eps") or print (1,"test.eps") or print -deps test.eps
to save the graphic as .eps and import it into latex it becomes grayscale.
Try
print -depsc test.eps
or
print -color -depsc test.eps
if the first one doesn't work.
EDIT:
Which graphics toolkit are you using? with gnuplot, it works just fine for me (Octave 3.6.2, Win XP) using the -eps flag.
you can use
print -dtex test.tex
Octave automatically exports your figure into LaTeX/Color EPS figure, with LaTeX fonts.
I am used to plot data with gnuplot, so I can easily put the figures in a LaTeX document, using the epslatex terminal. For example:
file = "data.dat"
set terminal epslatex
set output "figure1.tex"
plot file
This way, two files are generated: one .eps file, which contains the graphics, and one .tex file, which contains the text. The great advantage of this is that text is rendered by LaTeX, so the tics, labels, etc. have the same font as the rest of the document.
Now I am starting with matplotlib, which has a much nicer API, is more scriptable and, well, is Python. But, even though I can make matplotlib render the text with LaTeX, it gets embedded into the image and I cannot achieve the same advantages I had with gnuplot.
Is there any way I can emulate the epslatex terminal in matplotlib?
Update: matplotlib 1.2 introduced a new PGF/TikZ backend, and I have successfully used it for the exact purpose stated in this question: make LaTeX / XeTeX render the text of the plot. In the documentation there are some nice examples of plotting using the PGF backend, including custom preambles, custom fonts and full unicode math support.