Kapitel/Chapter 5

Einführung in LaTeX / Introduction into LaTeX

5.5

Colored lines with linebreak

% !TEX lualatex
\documentclass[12pt,a5paper]{article}%%% lualatex datei.tex
\usepackage{xcolor,luacolor}
\usepackage[soul]{lua-ul}
\newcommand\ulcol[2][black!15]{\highLight[#1]{\ul{#2}}}
\begin{document}
Lots of stuff is \ulcol{important enough to be highlighted, but only few things are
dangerous enough to deserve}
\ulcol[red]{red highlighting. Let's go back to traditional highlighting}.
\end{document} 

5.8

Stacked margin paragraphs

\documentclass{article}% Heiko Oberdiek
\usepackage{atbegshi,zref-abspage,picture}
\makeatletter
\providecommand*\c@zabspage{\c@abspage}
% * User macros for configuring
% \tbmparItemSep is inserted between marginal notes
% \tbmparMiddleSep is inserted between top and bottom marginal notes.
\newcommand*\tbmparItemSep{\vspace{1ex minus .5ex}\hrule\vspace{1ex minus .5ex}}
\newcommand*\tbmparMiddleSep{\vspace*{0pt plus 1fil}}
% * Debug messages
\newcommand*\tbmparDebug[1]{\typeout{[tbmpar] #1}}
% * Label management to remember absolute page number
%
% \tbmpar@PageByLabel stores and loads absolute page number from
% label and defines \tbmpar@page with absolute page number or
% zero if the label is not yet available.
\newcount\c@tbmpar@item
\c@tbmpar@item\z@
\newcommand*\tbmpar@PageByLabel{%
  \global\advance\c@tbmpar@item\@ne
  \zref@labelbyprops{tbmpar\the\c@tbmpar@item}{abspage}%
  \edef\tbmpar@page{%
    \zref@extractdefault{tbmpar\the\c@tbmpar@item}{abspage}{0}%
  }%
  \zref@refused{tbmpar\the\c@tbmpar@item}%
  \tbmparDebug{Item \the\c@tbmpar@item\space on page \tbmpar@page}%
}
% * Box register management
\newcount\c@tbmpar@box
\c@tbmpar@box\z@
\let\tbmpar@boxfreelist\@empty
% Get a new free box register either from the free list or,
% if the free list is empty, allocate a new box register.
\newcommand*\tbmpar@NextBox[1]{%
  \@next#1\tbmpar@boxfreelist{%  
    \tbmparDebug{Reused box: #1}%
  }{%
    \global\advance\c@tbmpar@box\@ne
    \expandafter\newbox\csname tbmpar@box\the\c@tbmpar@box\endcsname
    \edef#1{\csname tbmpar@box\the\c@tbmpar@box\endcsname}%
    \tbmparDebug{New box: #1}%
  }%
}
% Put free box in free list.
\newcommand*\tbmpar@FreeBox[1]{%
  \begingroup
    \let\@elt\relax
    \xdef\tbmpar@boxfreelist{%
      \tbmpar@boxfreelist
      \@elt#1%
    }%
    \tbmparDebug{Free box: #1}%
  \endgroup
}
\newsavebox\tbmpar@box

% Each marginpar is put in a box that is initialized as
% parbox/minipage.
\newcommand*\tbmparBoxSetup{}
\newcommand\tbmpar@VBox[1]{% 
  \vbox{%
    \color@begingroup
    \hsize\marginparwidth
    \edef\tbmpar@restore@ifminipage{%
      \if@minipage
        \noexpand\@minipagetrue
      \else
        \noexpand\@minipagefalse
      \fi
    }%   
    \@parboxrestore
    \@marginparreset
    \tbmparBoxSetup 
    #1%
    \tbmpar@restore@ifminipage
    \color@endgroup
  }%
}   
% Macro \tbmpar@marginpar looks for the page, where the margin note
% belongs to, stores the note in a box and appends the box to the  
% note collector register of the page.
% Each page is assigned a box collector registers that collect
% the top notes and a register that collect the bottom notes. 
% The name of the box register is \tbmpar@box. 
\newcommand\tbmpar@marginpar[4]{%
  \ifhmode
    \@bsphack
  \fi
  \tbmpar@PageByLabel
  \ifnum\tbmpar@page>\z@
    \setbox\tbmpar@box\tbmpar@VBox{#4}%
    \@ifundefined{tbmpar@#1box\tbmpar@page}{%
      \tbmpar@NextBox\tbmpar@currbox
      \global\expandafter\let
          \csname tbmpar@#1box\tbmpar@page\endcsname
          \tbmpar@currbox
      \global\setbox\tbmpar@currbox=\vbox{%
        \unvbox\tbmpar@box
      }%
    }{% 
      \tbmparDebug{Use box: \tbmpar@currbox}%
      \expandafter\let\expandafter\tbmpar@currbox
          \csname tbmpar@#1box\tbmpar@page\endcsname
      \global\setbox\tbmpar@currbox\tbmpar@VBox{%   
        \unvbox#2%
        \par
        \begingroup
          \tbmparItemSep
        \endgroup
        \unvbox#3%
      }%
    }%  
  \fi   
  \ifhmode
    \@esphack
  \fi
}
\newcommand*\topmarginpar{\tbmpar@marginpar{top}\tbmpar@currbox\tbmpar@box}
\newcommand*\botmarginpar{\tbmpar@marginpar{bot}\tbmpar@box\tbmpar@currbox}
% At shipout time we look for the box collector registers of this
% page and set these boxes in the marginpar box with respecting  
% \topskip and \maxdepth.
\AtBeginShipout{%
  \AtBeginShipoutUpperLeft{%
    \put(%
      \dimexpr 1in+\oddsidemargin+\textwidth+\marginparsep\relax,%
      -\dimexpr 1in+\topmargin+\headheight+\headsep+\textheight\relax
    ){%
      \begingroup
        \global\let\tbmpar@inuse=N%
        \setbox\tbmpar@box=\tbmpar@VBox{%
          \penalty-\@M
          \edef\tbmpar@tmp{tbmpar@topbox\the\value{zabspage}}%
          \@ifundefined{\tbmpar@tmp}{%
          }{%
            \expandafter\let\expandafter\tbmpar@currbox
                \csname\tbmpar@tmp\endcsname
            \unvbox\tbmpar@currbox
            \tbmpar@FreeBox\tbmpar@currbox
            \global\let\tbmpar@inuse=Y%   
          }%
          \endgraf
          \tbmparMiddleSep
          \edef\tbmpar@tmp{tbmpar@botbox\the\value{zabspage}}%
          \@ifundefined{\tbmpar@tmp}{%
          }{%
            \expandafter\let\expandafter\tbmpar@currbox
                \csname\tbmpar@tmp\endcsname
            \unvbox\tbmpar@currbox
            \tbmpar@FreeBox\tbmpar@currbox
            \global\let\tbmpar@inuse=Y%   
          }%
        }%  
        \ifx\tbmpar@inuse Y%
          \splittopskip=\topskip
          \setbox0=\vsplit\tbmpar@box to\z@
          \boxmaxdepth=\maxdepth
          \setbox\tbmpar@box=\vbox to\textheight{%
            \unvbox\tbmpar@box
          }%
          \box\tbmpar@box
        \fi
      \endgroup}}}     
\makeatother

\usepackage[a5paper,left=10mm,right=10mm,marginparwidth=40mm,includemp]{geometry}
\usepackage{microtype}
\usepackage[T1]{fontenc}
\usepackage{lmodern}

\clubpenalty=10000
\flushbottom
\settodepth\maxdepth{g}  
\setlength\fboxsep{1ex}
\usepackage{lipsum}
\usepackage{xcolor}
\newcommand*\shortlipsum{Lorem ipsum dolor sit amet, consectetuer adipiscing elit.}
\begin{document}
  \topmarginpar{\color{blue}\shortlipsum}
  \lipsum[1]
  \botmarginpar{%
    Show effect of \texttt{\textbackslash maxdepth}:
    $\displaystyle\sum_{\textstyle i=\frac{a}{g}}^\infty i = x$}
  \lipsum[2]
  \topmarginpar{\shortlipsum}%
  \botmarginpar{Second bottom marginal note}%
  \lipsum[3-4]
  \noindent a\botmarginpar{a} b\botmarginpar{b} c \botmarginpar{c} d\\
  e\\f\par
  \topmarginpar{\fbox{\shortlipsum}}
  \lipsum[5]
  Text with footnote and marginal note\footnote{Marginal note X}.
  \topmarginpar{This is marginal note X}
  \lipsum[6]
  \botmarginpar{\shortlipsum}
  \lipsum[7]  
\end{document}

5.9.1

Justification with a typewriter font

\documentclass{article}
\usepackage[english]{babel}
\usepackage{geometry,blindtext}
\usepackage{everysel}
\renewcommand*\familydefault{\ttdefault}
\begin{document}
\section{Default typesetting}
\blindtext

\section{With hyphenation}
\hyphenchar\font=`\-% to allow hyphenation
\blindtext

\section{With hyphenation and justification}
%\EverySelectfont{%
\fontdimen2\font=0.4em% interword space
\fontdimen3\font=0.2em% interword stretch
\fontdimen4\font=0.1em% interword shrink
\fontdimen7\font=0.1em% extra space
%\hyphenchar\font=`\-% to allow hyphenation
%}
\blindtext
\end{document}

5.9.4

Interwordspace and Emergencystretch

% !TEX lualatex
\documentclass[paper=a6,
	parskip=half-, % Absatzabstand halbe Zeile
	draft,         % Markiere overfull hbox 
]{scrartcl}
\usepackage[ngerman]{babel}
\usepackage{libertinus,luacode}
\newcommand\inMM[2][3]{\expandafter\inMMa\the#2\relax#1;}
{\catcode`\p=12 \catcode`\t=12 
 \gdef\inMMa#1pt\relax#2;{\luaexec{tex.print(string.format("\%.#2f",#1/2.845))}\,mm}}

\begin{document}
Die Staatsmedien berichten, dass Kim an einer Zeremonie teilgenommen hat, mit der die 
Fertigstellung einer Düngemittelfabrik gefeiert wurde. Aber das sagt nicht viel darüber aus, wie es 
ihm zuletzt ging. Das wissen wir also weiter nicht. Die vergangenen drei Wochen haben uns aber 
gezeigt, dass die Stabilität in der Region von einer Person abhängig ist, die ein gefährliches 
Atomwaffenprogramm kontrolliert.

\begin{hyphenrules}{nohyphenation}
Die Staatsmedien berichten, dass Kim an einer Zeremonie teilgenommen hat, mit der die 
Fertigstellung einer Düngemittelfabrik gefeiert wurde. Aber das sagt nicht viel darüber aus, wie es 
ihm zuletzt ging. Das wissen wir also weiter nicht. Die vergangenen drei Wochen haben uns aber 
gezeigt, dass die Stabilität in der Region von einer Person abhängig ist, die ein gefährliches 
Atomwaffenprogramm kontrolliert.
\end{hyphenrules}

\newpage
interword space: \the\fontdimen2\font=\inMM{\fontdimen2\font}: \hfill|\hspace{\fontdimen2\font}| 

plus value: \the\fontdimen3\font=\inMM{\fontdimen3\font}: 
\hfill|\hspace{\fontdimen2\font}\hspace{\fontdimen3\font}|

minus value: \the\fontdimen4\font=\inMM{\fontdimen4\font}: 
\hfill|\hspace{\fontdimen2\font}\hspace{-\fontdimen4\font}|

\setlength\emergencystretch{1cm}
Emergency stretch: \hfill|\hspace{\emergencystretch}|

\begin{hyphenrules}{nohyphenation}
Die Staatsmedien berichten, dass Kim an einer Zeremonie teilgenommen hat, mit der die 
Fertigstellung einer Düngemittelfabrik gefeiert wurde. Aber das sagt nicht viel darüber aus, wie es 
ihm zuletzt ging. Das wissen wir also weiter nicht. Die vergangenen drei Wochen haben uns aber 
gezeigt, dass die Stabilität in der Region von einer Person abhängig ist, die ein gefährliches 
Atomwaffenprogramm kontrolliert.
\end{hyphenrules}
\end{document}

5.10 (TeXnik)

Default justification (left/right-aligned)

\documentclass{article}
\usepackage{lipsum}
\makeatletter
\def\normaljustify{%
  \let\\\@normalcr\rightskip\z@skip \leftskip\z@skip 
  \parindent=20pt\parfillskip=0pt plus 1fil}
\makeatother
\begin{document}
\centering\lipsum[1]
\normaljustify\lipsum[1]
\end{document}

5.10.3 (wrapfig)

References to section titles instead of numbers

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{wrapfig}
\usepackage{xcolor}
\usepackage{lipsum}

\setlength{\parindent}{0pt}
\setlength{\parskip}{\baselineskip}

\newcommand*\WarningHead[1]{%
  \colorbox{black}{\parbox{\linewidth}{%
    \color{white}\textbf{#1}}}\vspace{10pt}}

\newcommand*\WrapFigure[1]{%
  \ifhmode\else\leavevmode\fi%
  \setlength\intextsep{-3pt}%
  \begin{wrapfigure}{r}[0pt]{0.3\linewidth}%
    \raggedleft% right align the figures
    \includegraphics[width=0.95\linewidth]{#1}%
  \end{wrapfigure}}

\begin{document}
\WrapFigure{foo}
\WarningHead{WARNING}
\lipsum[5]

\color{blue}
\WrapFigure{foo}
\WarningHead{WARNING}
\lipsum[5]
\end{document}

5.12 (Referenzen)

References to section titles instead of numbers

\documentclass{article}
\usepackage{nameref}
\begin{document}
\section{First section}\label{first}
This is section~\ref{first} with title \nameref{first}.
\subsection{Second subsection}\label{second}
This is subsection~\ref{second} with title \nameref{second}.
\subsubsection{Last subsubsection}\label{third}
This is subsubsection~\ref{third} with title \nameref{third}.
\end{document}

5.13 (Hyperlinks)

Links with special characters

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{hyperref}
\begin{document}
\href{http://de.wikipedia.org/wiki/Grunds%C3%A4tze_ordnungsm%C3%A4%C3%9Figer_Buchf%C3%BChrung}%
  {\nolinkurl{http://de.wikipedia.org/wiki/Grundsätze\_ordnungsmäßiger\_Buchführung}}%
\end{document}

5.3.1 KOMA-Script

Neue Gliederungsebene \subsubsubsection einfügen/define new section command \subsubsubsection

\documentclass[paper=a5,parskip=half-]{scrartcl}
\usepackage{libertinus}
\usepackage[ngerman]{babel}
\usepackage{blindtext}
\setcounter{tocdepth}{6} % setzt fest wie weit das Inhaltsverzeichnis zählen soll
\DeclareNewSectionCommand[%     Definition neuer section
  style=section,%               available are: part, chapter, or section
  level=4,%                     starts with -1=part
  indent=0mm,%                  The indentation of the title itself
  beforeskip=3.25ex plus 1ex minus 0.2ex,%  with optional stretch and shrink values
  afterskip= 1em,%              negative value -> no vertical skip but horizontal skip of +1em
  toclevel=4,
  tocstyle=subsection,%         for the toc use same style as subsection
  tocindent=7.0em,%             indentation in the toc
  tocnumwidth=4.1em%            width of a number, if there is any
]{subsubsubsection}
\renewcommand\thesubsubsubsection{% Redefinition der Zählweise
  \thesubsubsection.\arabic{subsubsubsection}}
\RedeclareSectionCommand[% setze eine Ebene tiefer, Rest bleibt gleich
  level=5,afterskip= 0.5ex plus -0.2ex minus -0.2ex,tocindent=8em]{paragraph}
\renewcommand\theparagraph{\thesubsubsubsection.\alph{paragraph}}  % Redefinition der Zählweise
\RedeclareSectionCommand[% % Ebenfalls eine Ebene tiefer
  level=6,afterskip= 0.5ex plus -0.2ex minus -0.2ex,toclevel=6]{subparagraph}
\renewcommand\thesubparagraph{\theparagraph.\alph{subparagraph}}  % Redefinition der Zählweise
\setcounter{secnumdepth}{6} % setzt, fest wie weit die Überschriften zählen sollen
\begin{document}

\tableofcontents
\section{Überschriftsebene 1} \blindtext
\subsection{Überschriftsebene 2} \blindtext
\subsubsection{Überschriftsebene 3} \blindtext
\subsubsubsection{Überschriftsebene 4} \blindtext
\paragraph{Ebene 5: paragraph} \blindtext
\paragraph{Ebene 5: paragraph} \blindtext
\subparagraph{Ebene 6: subparagraph} \blindtext
\end{document}

Zurück zur Hauptseite/Back to main page
Copyright $Id: chapter05.html 72 2023-09-07 12:46:26Z voss $