Dienstag, 24. Juni 2014

Redefine existing command in Latex

First you have to save your old existing \command to use it in the new redefined command via:
 \let\OLDcommand\command

Then you can redefine the exisiting command \command and use the old \OLDcommand:
 \renewcommand{\command}{this was \OLDcommand}

Sonntag, 1. Juni 2014

Latex write to a external file

To write to another text file in the latex document (FILE) you have to open it at the begin of the document and close it at the end of the document, like explained in the following:
\AtBeginDocument{%
  \Opensolutionfile{FILE}
}

\AtEndDocument{%
  \Closesolutionfile{FILE}
}

One can write to this file by using the following command:
\Writetofile{FILE}{text}

For example one could include the file at the end of the document by using:
  \IfFileExists{FILE.tex}{\input{FILE.tex}}{}

Define a new latex class

In order to define a new latex class you have to create a new file including the following statements as a header:
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{CLASSNAME}[CLASSCOMMENT]
\LoadClass{CLASS_TO_LOAD}

using this header a new class with name CLASSNAME is created (you can also define a comment CLASSCOMMENT) and by using \LoadClass all options of CLASS_TO_LOAD are loaded as predefined. Here as an example a dissertation class, based on the book class is defined:
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{dissertation}[class to write a perfect dissertation]
\LoadClass{book}

to load packages (e.g. graphicx) you need to use the following command:
\RequirePackage{graphixc}

in the follwing you can utilize
\newcommand{}{}
\renewcommand{}{}
 to define or change commands.

And use
\AtBeginDocument{}
\AtEndDocument{}
to execute commands at the beginning or end of the document.

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.