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.