TeXnik - Tips TeX and LaTeX


Welcome to the TeXnik website (under construction)

Miscellaneous Tips
TUG logo

Main page

Index
UK FAQ
Documentation
Software
CTAN
Search CTAN:

Statistics

Google c.t.t.

Google d.c.t.t.

 


 


addcontentsline - command | 
Barcode |  Border around each Page | 
circle with a letter in it |  Classfiles |  Color config file |  Current Time |  C++ - Symbol | 
Dashed underline |  Define a new Environment |  DNA-Sequences |  Dotted underline |  Double columnseprule |  Draft Option |  Drawing Math functions | 
Empty page |  Environment |  Environment in an environment (amsmath) |  epigraph-package | 
First Letter bold |  First Word in other fontsize | 
Graphics config file | 
Harpoon-Symbol |  hrulefill | 
Information about the (La)TeX System | 
jobname | 
LaTeX Length |  LaTeX System |  LaTeX Length | 
Mathcommands in textmode |  Motto on chapter-pages | 
\newenvironment | 
Overbracket |  Overwriting Images |  Overwriting Text | 
Package options |  Parameters in Environments |  Parsing filename |  Path-setting |  Picture on chapter-page |  Plot Math functions |  pstricks package | 
\raisebox Command |  \renewcommand{...} | 
Spanish Language |  Side by Side Example | 
Tally Symbol |  TeX System |  Time |  Timestamp |  twocolumn mode | 
Underbracket |  underscore | 
Width of an Image | 
xleft/rightharpoon-Symbol |  xypic and babel | 


Empty page

An empty page with a correct header and footer:

\newpage\null\newpage
Without header and footer, but correct page counting:
\newpage
\begingroup
  \thispagestyle{empty}% oder \pagestyle{empty}
  \null
\endgroup
\newpage
A "real" empty page, without influencing the counter:

\shipout\null

Modifying hrulefill

It is easy to modify the position and the width of the rule.
\makeatletter
\def\hrulefill{\leavevmode\leaders\hrule\@height-3pt\@depth7pt\hfill\kern\z@}
\makeatother
hrulefill.png

Parsing filename


Pass options to a package

When there are some problems with passing options to a package one can still use:
\PassOptionsToPackage{something}{pict2e}
\AtBeginDocument{\RequirePackage{pict2e}}
or from the command line
latex "\PassOptionsToPackage{dvips}{pict2e}\input{myfile}"
and when myfile loads pict2e without any specific options, the options on the command line will get used.

Stripping a prefix/suffix from a string

In the following example everything before the colon and itself is stripped. It is no problem to strip the suffix of the string instead of the prefix.

substr.png


\newenvironment
Put the code for a new environment into Layout->Preamble
\newenvironment{name}{%
	code for \begin{name}%
}{%
	code for \end{name}%
}
Using a parbox or a minipage requires some special code, f.ex.:
\makeatletter
\newenvironment{myEnv}{%
    \begin{lrbox}{\@tempboxa}%
% put here additional stuff
        \begin{minipage}{\columnwidth}%
% put here additional stuff
}{%
        \end{minipage}%
    \end{lrbox}%
    \usebox{\@tempboxa}%
}
\makeatother
In your text use it in the usual way:
\begin{myEnv}
	any stuff
\end{myEnv}


Side by Side Example

The package fancybox contains an environment for a "side by side example", which means on the left the code and on the right the output. This works well, but doesn't support umlauts or another special character. Here is a solution with package listings. sideBySideExample.png


\raisebox - command


xypic and babel
The xy-package redefines the catcode for " which causes problems with babel. So still use it in the following way:
\shorthandoff{"}
% xypic stuff
\shorthandon{"}


addcontentsline - command
If you want to add more than one line to one of the toc/lot/... use
\addcontentsline{toc}{section}{%
  line 1\hspace*{\fill}\endgraf
  line 2%
}
For the addtocontents -command see also here
Information about the installed (La)TeX System
If you need some information about your local TeX system try the following commands to get information about teTeX, TeX Directory Structure and pathsettings:
voss@shania:/tmp> texdoc TETEXDOC  (creates and opens a pdf document)
voss@shania:/tmp> texdoc tds  (creates and opens a pdf document)
voss@shania:/tmp> less `kpsewhich texmf.cnf`  (opens the configuration file)
voss@shania:/tmp> kpsewhich '-expand-var=$HOMETEXMF'
/usr/local/texlive/texmf-local

voss@shania:/tmp> kpsewhich '-expand-var=$HOMETEXMF'
/usr/local/texlive/texmf-local
voss@shania:/tmp> kpsewhich -expand-var=\$TEXMF
{!!/home/voss/.texlive2005/texmf-config,!!/home/voss/.texlive2005/texmf-var,/home/voss/texmf,!!/usr/local/texlive/2005/texmf-config,!!/usr/local/texlive/2005/texmf-var,!!/usr/local/texlive/2005/texmf,!!/usr/local/texlive/2005/../texmf-local,!!/usr/local/texlive/2005/texmf-dist}

voss@shania:/tmp> kpsewhich -expand-var=\$TEXINPUTS
:/home/voss/.TeX:/usr/share/doc/.TeX:/usr/doc/.TeX
The last one prints the root of the TeX tree.

This one tells you where LaTeX search for tex or bib files

voss@shania:/tmp> kpsepath tex
.:!!/home/voss/.texlive2005/texmf-config/tex/kpsewhich//:
!!/home/voss/.texlive2005/texmf-var/tex/kpsewhich//:
/home/voss/texmf/tex/kpsewhich//:
!!/usr/local/texlive/2005/texmf-config/tex/kpsewhich//:
!!/usr/local/texlive/2005/texmf-var/tex/kpsewhich//:
!!/usr/local/texlive/2005/texmf/tex/kpsewhich//:
!!/usr/local/texlive/2005/../texmf-local/tex/kpsewhich//:
!!/usr/local/texlive/2005/texmf-dist/tex/kpsewhich//:
!!/home/voss/.texlive2005/texmf-config/tex/generic//:
!!/home/voss/.texlive2005/texmf-var/tex/generic//:
/home/voss/texmf/tex/generic//:
!!/usr/local/texlive/2005/texmf-config/tex/generic//:
!!/usr/local/texlive/2005/texmf-var/tex/generic//:
!!/usr/local/texlive/2005/texmf/tex/generic//:
!!/usr/local/texlive/2005/../texmf-local/tex/generic//:
!!/usr/local/texlive/2005/texmf-dist/tex/generic//:
!!/home/voss/.texlive2005/texmf-config/tex///:
!!/home/voss/.texlive2005/texmf-var/tex///:
/home/voss/texmf/tex///:!!/usr/local/texlive/2005/texmf-config/tex///:
!!/usr/local/texlive/2005/texmf-var/tex///:!!/usr/local/texlive/2005/texmf/tex///:
!!/usr/local/texlive/2005/../texmf-local/tex///:
!!/usr/local/texlive/2005/texmf-dist/tex///:/home/voss/.TeX:/usr/share/doc/.TeX:
/usr/doc/.TeX

voss@shania:/tmp> kpsepath bib
.:!!/home/voss/.texlive2005/texmf-config/bibtex/bib//:
!!/home/voss/.texlive2005/texmf-var/bibtex/bib//:
/home/voss/texmf/bibtex/bib//:!!/usr/local/texlive/2005/texmf-config/bibtex/bib//:
!!/usr/local/texlive/2005/texmf-var/bibtex/bib//:
!!/usr/local/texlive/2005/texmf/bibtex/bib//:
!!/usr/local/texlive/2005/../texmf-local/bibtex/bib//:
!!/usr/local/texlive/2005/texmf-dist/bibtex/bib//
  • To get all valid options write kpsepath.
  • For document internal path settings go here

  • Command Characters / Underscore
    In LaTeX the characters $ % { } & # _ ^ are command characters and have to be escaped when you want to use them as normal characters:
    \$ \% \{ \} \& \# \_ \^
    otherwise you'll get an error at the LaTeX run.

    For the underscore there exists a special package underscore.sty. If you want to pass for example a filename with a underscore to another macro, then do it in the following way:

    \documentclass[12pt]{article}
    \usepackage{graphicx}
    \newcommand{\UnderscoreCommands}{\do\myMacro}
    \newcommand{\myMacro}[1]{something ... \includegraphics{#1}}
    \usepackage[strings]{underscore}
    \begin{document}
        \myMacro{/tmp/file_1}
    \end{document}
    For a document which has bookmarks with a underscore it is a bit different:
    \documentclass{article}
    \usepackage{hyperref}
    \usepackage{underscore}
    \begingroup
      \lccode`\~=`\_
    \lowercase{\endgroup
      \pdfstringdefDisableCommands{\let~\relax}%
    }
    \begin{document}
    \tableofcontents
    \section{Hello_World}
    \end{document}


    C++ - Symbol

    \makeatletter
    \DeclareRobustCommand{\Cpp}
    {\valign{\vfil\hbox{##}\vfil\cr
       \textsf{C\kern-.1em}\cr
       $\hbox{\fontsize{\sf@size}{0}\textbf{+\kern-0.05em+}}$\cr}%
    }
    \makeatother


    Parameter in an Environment

    If you want to use a parameter in the closing part of an environment, than first define a dummy command. For example:
    \newenvironment{mytable}[2]{%
      \begin{table}%
        \newcommand{\mytablecaption}{%
          \caption{#1}%
          \label{#2}%
        }%
        \centering
        \begin{tabular}{lll}%
    }{%
        \end{tabular}%
        \mytablecaption
      \end{table}%
    }
    


    Width of an Image

    in latex preamble

     \newsavebox{\Imagebox}
    \newcommand{\image}[2]{
      \centering
      \savebox{\Imagebox}{\includegraphics{#1}}%
       \usebox{\Imagebox}\par\noindent
       \parbox[t]{\wd\Imagebox}{\#2}%
    } 
    Now you are able to place an image in a parbox with the right width.


    Path for files

    in latex preamble for files

     \def\input@path{{yourInputPathForTheFiles/}} 

    For the graphi files you can define:

     \graphicspath{{../home/voss/TEST/}} 
    but remember:
  • you can't have an absolute path as an argument!
  • for a global, TeX system wide path setting go go here.

  • draft-Option
    In some cases it makes sense when LaTeX shows problematic formatting with vertical margin rules and the graphics as empty rectangles in the dvi-output. In this case choose the option draft for the documentclass.

    If you want to use this option for own commands like notes, than you can use this option and output some notes only when the draft option is set. The following example shows this for the arcticle class:

    \newcommand{\myNote}[1]{%
       \@ifclasswith{article}{draft}{%
         \marginpar{#1}}{}%
    }
    The draft-option is passed to all other used packages. If you only want to mark the overfull lines then you can write
    \setlength{\overfullrule}{5pt}
    instead of using the draft-option with all other effects.


    Overwriting text
    Use package soul.sty or try the following commands. Overwriting like is possible with command \myOverwrite{demo}{xxxxx}, which is defined in LaTeX-preamble
    \newcommand\myOverwrite[2]{\makebox[0cm][l]{#1}#2\ } 
    You can also define your own math-symbols:

    \myOverwrite{$\parallel$}{$\slash$}
    \myOverwrite{\raisebox{0.15ex}{o}}{$\slash$}


    circle with letter in it
    \newcommand\kreis[1]{\ensuremath{\mathbin{\settowidth{\dimen7}{\mbox{$\bigcirc$}}%
                  \makebox[0pt][l]{$\bigcirc$}\makebox[\dimen7]{#1}}}}
    \kreis{u} prints a circle with an u in it.


    Mathcommands in textmode
    If you are tired of writing some math-commands in mathmode, while they can't be written in textmode, like $\delta$, you can redefine these commands:
    \usepackage{xspace} %for a better layout
    \let\origdelta\delta 
    \renewcommand{\delta}{\ensuremath{\origdelta}\xspace}
    Now you can write only \delta, LaTeX uses it by default as a math-command like:
    \delta and $delta$ is exactly the same ...


    Barcode

    barcode0.png

    See also the PSTricks package pst-barcode.

    Environment in an environment
    You cannot create a new environment which uses a given amsmath environment. With the following amsmath macro it is possible.

    local time: Wed Oct 16 21:16:52 CEST 2019 ; file is: 112.04849537037 days old
    contact webmaster _at_ TeXnik.de