Sonntag, 1. Juni 2014

Change latex command when compiling inside emacs

Emacs adds the following comment commands into a multiple latex file to know which commands to use and to define the master file:
%%% Local Variables: 
%%% mode: latex
%%% TeX-master: t
%%% End:

In order to define the latex command e.g. include -shell-escape you have to add the following line before the End: command into the latex file:
%%% LaTeX-command: "latex -shell-escape" 

Latex define new "section-type"

To define a new section-type you need to use the titlesec Package:
\usepackage{titlesec}

to define a new section-type you use the titleclass command with name NAME and copy the properties of \PART (e.g. \section)
\titleclass{\NAME}{option}[\PART]

additionally you need a new counter and a command that gives back the counter:
\newcounter{NAME}
\renewcommand{\theNAME}{\arabic{NAME}} 

finally you can define the titleformat and titlespacings:
\titleformat{\NAME}[hang]
  {\normalfont }                      % format of titletext
  {{\bf Task \theNAME:} }      % command before titletext
  {0pt}                                      % spacing after titletext
  {}                                           % before code
  []                                           % after code
\titlespacing{\NAME}{0pt}{*4}{*2}

With options explained here:
\titlespacing*{command}{left}{before-sep}{after-sep}
For a more detailed description look into the titlesec documentatio, but these are the most important points.

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".