Montag, 28. April 2014

make gnuplot produce a latex standalone document

gnuplot has a view very good terminals including the epslatex-terminal the only backdraw which i had recently was that the terminal produces either:
- a latex file which can be included in the latex-document
or
- a latex-document which produces a pdf with the minimal-documentclass
but it does not produce a document which can be used via includestandalone.

But now I found a way to do it.

1.  create example with epslatex terminal


set terminal epslatex
set output "test.tex"
plot sin(x)
set output

2. Add preamble for standalone figure and add \end{document}

Add at the beginning of test.tex:
 \documentclass{standalone}
\usepackage{graphicx}
\begin{document}

Add at the end of test.tex
\end{document}

PS: I also wrote a gnuplot script doing all of this:

epslatexterm(name, xsize, ysize, gnuplotcommand) = sprintf('\
name="%s";\
file=name.".tex";\
set terminal epslatex size %s, %s;\
%s;\
set output name.".tex";  \
replot; \
unset output;\
eval bash(''echo \" \\\\begin{document}            \" |cat - ''.file.'' > tmp    '');\
eval bash(''echo \" \\\\usepackage{graphicx}       \" |cat - tmp      > tmp2   '');\
eval bash(''echo \" \\\\documentclass{standalone}  \" |cat - tmp2     > tmp    '');\
eval bash(''echo \" \\\\end{document}              \" |cat tmp -      > tmp2   '');\
eval bash("sed ''s/".name."/".name."-inc/g'' tmp2 > ".file  );\
eval bash(''mv ''.name.''.eps ''.name.''-inc.eps'');\
eval bash(''rm tmp tmp2 -f'');\
set terminal wxt; \
',name,xsize,ysize,gnuplotcommand)

Mittwoch, 9. April 2014

set password for a pdf-file

To add a password to a pdf you can simply use pdftk and have it add a password as follows:

pdftk original.pdf output new.pdf user_pw PROMPT

You will get a prompt asking for the password, which in turns will be added to your pdf-file.

Freitag, 24. Januar 2014

imagemagick convert pdf to jpg

To convert a pdf file in a image file, the best option is to use imagemagick, which means convert. The only option you have to define is the density, which can be defined as follows:
convert -density 300 test.pdf test.jpg


Donnerstag, 16. Januar 2014

pdftk extract pages of pdf-file

Extract PAGES from input.pdf into output.pdf via:

pdftk A=input.pdf cat A${PAGES} output output.pdf

for more information use:
man pdftk

latex mix colors with colorlet and xcolor

To mix colors you need to have the xcolor package loaded first via:

\usepackage{xcolor}

And then you can mix two colors with

\colorlet{DarkBlue}{blue!80!black}
which means you mix 80% blue with 20% black. If you do not have a second color you mix the first with: "white".

Dienstag, 14. Januar 2014

latex tables with package booktabs

Latex tables

To use the latex booktabs package simply include:
\usepackage{booktabs}
in the header.

After this you can make a nice table via:
\begin{table}[h!]
  \begin{tabular}{ l l l}
    \toprule
    First & Second  & Third \\
    \midrule
    1 & 2 & 3 \\
    1 & 2 & 3 \\
    1 & 2 & 3 \\
    1 & 2 & 3 \\
    1 & 2 & 3 \\
    \bottomrule
  \end{tabular}
\end{table}



for further tips read the booktabs manual.

Donnerstag, 12. Dezember 2013

Bash combining files

Combine files side by side columnwise:

If you have two files one of them consisting of one column and another file consisting of one column as well you can join the files by using:
paste file1 file2

Combine files one after the other:

Simply use:
cat file1 file2
which will first print file1 and then file2.

The "join" command:

Additionally there is also the join command which will print data which is present in file1 and file2, e.g.:
join file1 file2
If file1 and file2 share the same string in one line it gets printed to standard out.