Mittwoch, 22. Oktober 2014

histogram with gnuplot

if you want to plot a histogram with gnuplot, just use the raw data in "data.dat" and plot the data via the following command:

the data is transformed into a histogram via the bin function and then plotted via the plot with boxes command.

  #!/usr/bin/gnuplot

file="data.dat"
binwidth=1.0
bin(x,width)=width*floor(x/width)
set style fill solid 0.5

plot file u (bin($1,binwidth)):(1.0) smooth freq with boxes ls 1 t 'total'


the result looks something like that:

Freitag, 10. Oktober 2014

remove zero sized file

To delete zero sized files in bash you can simply use an if clause with you can put in a loop. First the if clause

  if [ ! -s file ] ; then
    rm file
 fi

and finally the full loop:

 for file in *
 do
   if [ ! -s $file ] ; then
     rm $file
   fi
 done

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"