LaTeX: Marko und Umgebungen / Macro and Environments

Makros

YouTube

Wolfgang Dautermann: Programmierung mit LaTeX
Wolfgang Dautermann: Programmierung mit LaTeX (PDF)

tug.org

LaTeX2e unofficial reference manual (October 2018)

Overleaf

TeX primitives listed by TeX engine
How Overleaf created the TeX primitive reference data
How TeX macros actually work
How does \expandafter work: An introduction to TeX tokens
How does \expandafter work: From basic principles to exploring TeX’s source code
Commands
Latex typesetting is made by using special tags or commands that provide a handful of ways to format your document. Sometimes standard commands are not enough to fulfil some specific needs, in such cases new commands can be defined and this article explains how.

TeXFAQ

Using Plain or primitive commands in LaTeX
How to print contents of variables?

texwelt.de

Was machen eigentlich \makeatletter und \makeatother?

StackExchange

Difference between LaTeX, LaTeX2e, LaTeX3 ?
Is there a list of expandable TeX primitives? LaTeX? e-TeX? others?

Einführung in das Textsatzsystem LATEX – Komplexe Makros und Befehle

Plain TeX

\def<Befehlsname><Argument(e)>{<Befehlsdefinition>}
\let<neuer Befehlsname><alter Befehlsname>

\def\mymakro#1#2{Makro mit zwei Argumenten #1 und #2}
let\newmakro\oldmakro

LaTeX 2

\(re)newcommand{<Befehlsname>}
  [<Anzahl der Argumente>]
  [<Default für erstes (optionales) Argument>]
  {<Befehlsdefinition>}

\newenvironment{<Umgebungsname>}
  [<Anzahl der Argumente>]
  [<Default für erstes (optionales) Argument>]
  {<Definition Code vor Umgebung>}
  {<Definition Code nach Umgebung>}

LaTeX 3

Mit Paket xparse verfügbar:
\NewDocumentCommand, \RenewDocumentCommand, \NewDocumentEnvironment, ...

\NewDocumentCommand{<Befehlsname>}
  {<Argumentstrukturi}
  {<Definitioni}

Einfache Makros in TEX und LATEX (PDF)

Plain TeX

\def\name{definition}
\def\name#1{definition, die #1 benutzt}
\def\name#1#2{definition, die #1 und #2 benutzt} % bis #9
\def\name zkette#1zkette#2zkette {definition, die #1 und #2 benutzt}

Ohne Parameter

\def\hrz{Hochschulrechenzentrum (HRZ)}

Vortext \hrz Nachtext
Vortext Hochschulrechenzentrum (HRZ)Nachtext (ohne Abstand)

Vortext \hrz\ Nachtext
Vortext \hrz{} Nachtext
Vortext {\hrz} Nachtext
Vortext Hochschulrechenzentrum (HRZ) Nachtext (mit Abstand)

Mit mehreren Parametern

% Makro bild
% #1 : Grafikdatei
% #2 : Bildunterschrift
% #3 : Verweis-Label
\def\bild#1#2#3{%
\begin{figure}[htp]
\centering
\includegraphics{#1}
\vspace{0.5cm}
\caption{#2}\label{#3}
\end{figure}
}

\bild{template-1.png}{Eine Kr¨ote oder ein Frosch}{fig:1}

Eingabemuster

% Makro ganzwichtig
% #1 : Farbe
% #2 : Text
\def\ganzwichtig(#1 in #2){\fbox{\textcolor{#2}{#1}}}
% .................................
% Makro referenz
% #1 : Gattung (Abbildung, Tabelle)
% #2 : Verweisziel
\def\referenz#1#2{#1~\ref{#2} auf Seite~\pageref{#2} }

Das ist \wichtig{neu} und das \ganzwichtig(ganz neu in red).
Siehe \referenz{Abbildung}{fig:1}

LaTeX-Art

\newcommand{\name}{definition}
\newcommand{\name}[1]{definition, die #1 benutzt}
\newcommand{\name}[2]{definition, die #1 und #2 benutzt} % bis #9

\renewcommand       (Re-Definition)
\providenewcommand  (Re-Definition oder Neu-Definition)
\newcommand*
\renewcommand*
\providenewcommand*

Ohne Parameter

\newcommand{\HRZ}{Hochschulrechenzentrum (HRZ)}

Vortext \hrz Nachtext
Vortext Hochschulrechenzentrum (HRZ)Nachtext (ohne Abstand)

Vortext \hrz\ Nachtext
Vortext \hrz{} Nachtext
Vortext {\hrz} Nachtext
Vortext Hochschulrechenzentrum (HRZ) Nachtext (mit Abstand)

Mit mehreren Parametern

% Makro Bild
% #1 : Grafikdatei
% #2 : Bildunterschrift
% #3 : Verweis-Label
\newcommand{\Bild}[3]{%
\begin{figure}[htp]
\centering
\includegraphics{#1}
\vspace{0.5cm}
\caption{#2}\label{#3}
\end{figure}
}

\Bild{template-2.png}{Ein Waldsee}{fig:2}

Eingabemuster – so einfach geht das in LATEX nicht

% Makro Ganzwichtig
% #1 : Farbe
% #2 : Text
\newcommand{\Ganzwichtig}[2]{\fbox{\textcolor{#1}{#2}}}

Das ist \WICHTIG{neu} und das \Ganzwichtig{red}{ganz neu}.
Siehe \Referenz{Abbildung}{fig:2}

Interne Makros

Was machen eigentlich \makeatletter und \makeatother?

LaTeX 2e

@ für interne Makros

\makeatletter % setzt Kategorie-Code von @ auf 11
<Code mit Befehlen, die @ im Namen haben>
\makeatother % setzt Kategorie-Code von @ auf 12

\makeatletter
\def\name#1{\gdef\@name{#1}}
\makeatother

LaTeX 3

: und _ für interne Makros

\usepackage{expl3}
\ExplSyntaxOn
[...]
\ExplSyntaxOff

Umgebungen

What are LaTeX “environments”
While TeX makes direct provision for commands, LaTeX adds a concept of “environment”; environments perform an action on a block (of something or other) rather than than just doing something at one place in your document.

Overleaf: Environments
Environments are used to format blocks of text in a LATEX documents. This article explains how to use environments and how to define new ones.

List of LaTeX environments

  • Float environments:
    figure, table
  • List environments:
    description, enumerate, itemize, list
  • Math environments:
    math, displaymath, array, eqnarray, equation [subequations, multiline, gather], theorem
  • Matrix environments:
    matrix, pmatrix, bmatrix, Bmatrix, vmatrix, Vmatrix, smallmatrix
  • Cases environment:
    cases
  • Align environments:
    align, alignat, flalign
  • Paragraph environments:
    center, flushleft, flushright, minipage, quotation, quote, verbatim, verse
  • Paragraph commands:
    centering, raggedright, raggedleft, parbox, footnote, footnotetext, verb
  • Picture environment:
    picture
  • Picture commands:
    \circle, \dashbox, \frame, \framebox, \line, \linethickness, \makebox, \multiput, \oval, \put, \shortstack, \vector
  • Table environments:
    tabbing, tabular

TeX Primitive Control Sequences

TeX Primitive Control Sequences

Control Sequences
Family NULL Type Description
Box Logic c Command
Character Macro d Derived Command
Debugging Marks iq Internal Quantity
File I/O Math pi Parameter (integer)
Fonts Page pd Parameter (dimen)
Glue Paragraph pg Parameter (glue)
Hyphenation Penalties pm Parameter (muglue)
Inserts Registers pt Parameter (token)
Job Tables
Kern

Leave a Reply

Your email address will not be published. Required fields are marked *