Posts tagged ‘LaTeX’

Schöne Matrizen mit nicematrix

Um ansprechende Matrizen zu setzen gibt es mit dem nicematrix Paket ein recht neues Paket, das sich alle anschauen sollten, die viel mit Matrizen zu tun haben. Die folgenden Beispiele sind der Dokumentation entnommen, teilweise braucht man mehrere LaTeX-Läufe für das finale Ergebnis.

%!TEX TS-program = Arara
% arara: pdflatex: {shell: yes}
\documentclass[12pt,ngerman]{scrartcl}
 
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{babel}
\usepackage{xcolor} 
 
\usepackage{tikz}
\usepackage{siunitx}
\usepackage{nicematrix}
\NiceMatrixOptions{cell-space-top-limit = 1pt,cell-space-bottom-limit = 1pt}
\begin{document}
 
\begin{equation}
\begin{pmatrix}
\frac12 & -\frac12 \\
\frac13 & \frac14 \\
\end{pmatrix}
=
\begin{pNiceMatrix}
\frac12 & -\frac12 \\
\frac13 & \frac14 \\
\end{pNiceMatrix}
\end{equation}
 
\begin{equation}
A = \begin{pNiceMatrix}[baseline=2]
\frac{1}{\sqrt{1+p^2}} & p & 1-p \\
1 & 1 & 1 \\
1 & p & 1+p
\end{pNiceMatrix}
\end{equation}
 
 
\NiceMatrixOptions{cell-space-top-limit=1pt,cell-space-bottom-limit=1pt}
 
\begin{equation}
A=\begin{pNiceArray}{cc|cc}[baseline=line-3]
\dfrac1A & \dfrac1B & 0 & 0 \\
\dfrac1C & \dfrac1D & 0 & 0 \\
\hline
0 & 0 & A & B \\
0 & 0 & D & D \\
\end{pNiceArray}
\end{equation}
 
 
\begin{equation}
\begin{NiceArray}{*{5}{c}}[hvlines]
\diagbox{x}{y} & e & a & b & c \\
e & e & a & b & c \\
a & a & e & c & b \\
b & b & c & e & a \\
c & c & b & a & e
\end{NiceArray}
\end{equation}
 
 
\NiceMatrixOptions{code-for-first-row = \color{red},
code-for-first-col = \color{blue},
code-for-last-row = \color{green},
code-for-last-col = \color{magenta}}
 
\begin{equation}
\begin{pNiceArray}{cc|cc}[first-row,last-row=5,first-col,last-col,nullify-dots]
& C_1 & \Cdots & & C_4 & \\
L_1 & a_{11} & a_{12} & a_{13} & a_{14} & L_1 \\
\Vdots & a_{21} & a_{22} & a_{23} & a_{24} & \Vdots \\
\hline
& a_{31} & a_{32} & a_{33} & a_{34} & \\
L_4 & a_{41} & a_{42} & a_{43} & a_{44} & L_4 \\
& C_1 & \Cdots & & C_4 &
\end{pNiceArray}
\end{equation}
 
\begin{equation}
\begin{pNiceArray}{ScWc{1cm}c}[nullify-dots,first-row]
{C_1} & \Cdots & & C_n \\
2.3 & 0 & \Cdots & 0 \\
12.4 & \Vdots & & \Vdots \\
1.45 \\
7.2 & 0 & \Cdots & 0
\end{pNiceArray}
\end{equation}
 
\[\begin{NiceMatrix}[
code-before =
{
\tikz \draw [fill = red!15]
(row-7-|col-4) -- (row-8-|col-4) -- (row-8-|col-5) --
(row-9-|col-5) -- (row-9-|col-6) |- cycle ;
}
]1
\\
1 & 1 \\
1 & 2 & 1 \\
1 & 3 & 3 & 1 \\
1 & 4 & 6 & 4 & 1 \\
1 & 5 & 10 & 10 & 5 & 1 \\
1 & 6 & 15 & 20 & 15 & 6 & 1 \\
1 & 7 & 21 & 35 & 35 & 21 & 7 & 1 \\
1 & 8 & 28 & 56 & 70 & 56 & 28 & 8 & 1
\end{NiceMatrix}\]
 
 
\(
\begin{bNiceMatrix}
C[a_1,a_1] & \Cdots & C[a_1,a_n]
& \hspace*{20mm} & C[a_1,a_1^{(p)}] & \Cdots & C[a_1,a_n^{(p)}] \\
\Vdots & \Ddots & \Vdots
& \Hdotsfor{1} & \Vdots & \Ddots & \Vdots \\
C[a_n,a_1] & \Cdots & C[a_n,a_n]
& & C[a_n,a_1^{(p)}] & \Cdots & C[a_n,a_n^{(p)}] \\
\rule{0pt}{15mm} & \Vdotsfor{1} & & \Ddots & & \Vdotsfor{1} \\
C[a_1^{(p)},a_1] & \Cdots & C[a_1^{(p)},a_n]
& & C[a_1^{(p)},a_1^{(p)}] & \Cdots & C[a_1^{(p)},a_n^{(p)}] \\
\Vdots & \Ddots & \Vdots
& \Hdotsfor{1} & \Vdots & \Ddots & \Vdots \\
C[a_n^{(p)},a_1] & \Cdots & C[a_n^{(p)},a_n]
& & C[a_n^{(p)},a_1^{(p)}] & \Cdots & C[a_n^{(p)},a_n^{(p)}]
\end{bNiceMatrix}
\)
 
\end{document}

Uwe

Uwe Ziegenhagen likes LaTeX and Python, sometimes even combined. Do you like my content and would like to thank me for it? Consider making a small donation to my local fablab, the Dingfabrik Köln. Details on how to donate can be found here Spenden für die Dingfabrik.

More Posts - Website

Das subcaption Paket als subfigure Ersatz

Um mehreren nebeneinander gesetzten Bildern separate Bildunterschriften zu geben, war das subfigure Paket lange Standard. Mit dem subcaption Paket von Axel Sommerfeldt gibt es einen würdigen Nachfolger, der aktiv gepflegt wird.

Hier ein Beispiel, zum Übersetzen bitte eigene Bilder nutzen:

\documentclass[12pt,ngerman]{scrartcl}
 
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{babel}
\usepackage{graphicx}
\usepackage{subcaption}
 
\begin{document}
 
\begin{figure}
\centering
\subcaptionbox{Eine Katze \label{cat1}}
{\includegraphics[width=0.49\textwidth]{Bilder/Katze1}}
\subcaptionbox{Die selbe Katze \label{cat2}}
{\includegraphics[width=0.49\textwidth]{Bilder/Katze2}}
\caption{Zwei Katzenbilder}\label{katzenbilder}
\end{figure}
 
Abbildung \ref{cat1} auf Seite \pageref{katzenbilder}
 
Abbildung \ref{cat2} auf Seite \pageref{katzenbilder}
 
Abbildung \ref{katzenbilder} auf Seite \pageref{katzenbilder}
 
\end{document}

Uwe

Uwe Ziegenhagen likes LaTeX and Python, sometimes even combined. Do you like my content and would like to thank me for it? Consider making a small donation to my local fablab, the Dingfabrik Köln. Details on how to donate can be found here Spenden für die Dingfabrik.

More Posts - Website

Flyer mit LaTeX gestalten

Um einen einfachen Flyer zu erstellen gibt es nichts besseres als die leaflet-Klasse. Hier ein einfaches Beispiel, die Katzenbilder muss man zum Übersetzen auskommentieren oder ersetzen.

\documentclass[12pt,ngerman]{leaflet}
 
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{booktabs}
\usepackage{babel}
\usepackage{graphicx}
\usepackage{csquotes}
\usepackage{paralist}
\usepackage{xcolor}
\usepackage{palatino}
\usepackage{blindtext}
\usepackage{microtype}
 
\author{Uwe Ziegenhagen}
\title{Mein erster Flyer}
 
\begin{document}
\maketitle
\thispagestyle{empty}
 
\section{Foo}
 
\blindtext[2]
 
\section{Bar}
 
\includegraphics[width=\textwidth]{Bilder/Katze2}
 
\blindtext
 
\section{Hello}
 
\blindtext[4]
 
\section{World}
 
\blindtext
 
\section{Hallo Welt}
 
\blindtext
 
\includegraphics[width=\textwidth]{Bilder/Katze1}
 
\end{document}

leaflet-01

Uwe

Uwe Ziegenhagen likes LaTeX and Python, sometimes even combined. Do you like my content and would like to thank me for it? Consider making a small donation to my local fablab, the Dingfabrik Köln. Details on how to donate can be found here Spenden für die Dingfabrik.

More Posts - Website

CTAN-Pakete per REST-API hochladen

Vermutlich ist es nicht so bekannt, dass man LaTeX-Pakete auch per REST-API auf CTAN hochladen kann. Das ist insbesondere dann praktisch, wenn man öfter Pakete aktualisieren muss, wie ich es beispielsweise mit der DTK Bibliografie mehrmals im Jahr mache.

Manfred Lotz vom CTAN-Team hat dazu ein Python-Skript geschrieben (https://gitlab.com/Lotz/pkgcheck/blob/master/ctan_upload.py), das diese API befüttert.

Ich habe sein Skript noch ein wenig angepasst (ich erstelle auch die ZIP-Datei damit und kopiere die richtigen Dateien an ihren Platz), mein Skript findet ihr im Github unter https://github.com/dante-ev/dtk-bibliography/blob/master/pack_and_upload_to_ctan.py. Für den Upload selbst benötigt man noch eine TOML-Datei, in der die Upload-Informationen als Key-Value-Paare stehen. Ein Beispiel für eine solche TOML-Datei findet ihr bei Manfred unter https://gitlab.com/Lotz/pkgcheck/-/blob/master/pkgcheck.toml.

Uwe

Uwe Ziegenhagen likes LaTeX and Python, sometimes even combined. Do you like my content and would like to thank me for it? Consider making a small donation to my local fablab, the Dingfabrik Köln. Details on how to donate can be found here Spenden für die Dingfabrik.

More Posts - Website

Lose-Blatt-Sammlungen mit LaTeX

Für ein spezielles Projekt habe ich eine Möglichkeit gesucht, eine Lose-Blatt-Sammlung mit LaTeX zu gestalten. Lose-Blatt-Sammlung heißt in dem Zusammenhang:

1) Für jede (logische) Seite existiert ein separates Unterdokument.

2) Im Dateinamen jedes Unterdokuments ist die Seitennummer enthalten.

3) Einzelne Seiten können dadurch problemlos ausgetauscht werden, ohne dass sich die Seitenzahlen der anderen Seiten ändern.

4) Jedes Unterdokument besteht grundsätzlich aus nur einer physischen Textseite, kann jedoch auch länger sein. Daher hat jedes Unterdokument eine Seitennummerierung der Form xx-yy. xx steht dabei für die logische Seitennummer im Hauptdokument, die aus dem Dateinamen gezogen wird, yy für die fortlaufende (physische) Seitennummer im Unterdokument selbst. Die fortlaufende Seitennummer für das Gesamtdokument werte ich nicht aus.

5) Alle Dokumente stehen natürlich unter Versionverwaltung, hier nutze ich Subversion.

Wie habe ich es umgesetzt?

Das Hauptdokument sieht wie folgt aus. Neben dem svn-multi Paket, das die Subversion-Daten bereitstellt, nutze ich varsfromjobname, um die einzelnen Komponenten der Dateinamen (xx-yy.tex) auswerten zu können. Die einzelnen Teile von Kopf- und Fußzeile werden durch scrlayer-scrpage modifiziert.

%!TEX TS-program = Arara
% arara: pdflatex: {shell: yes}
% arara: pdflatex: {shell: yes}
 
\documentclass[12pt,ngerman,headsepline,footsepline]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{babel}
\usepackage{csquotes}
\usepackage{xcolor}
\usepackage{svn-multi}
\usepackage{currfile}
\usepackage{varsfromjobname}
 
\usepackage{blindtext}
\addtokomafont{pagenumber}{\textit}
\addtokomafont{sectionentrypagenumber}{\color{white}}
\usepackage[left=3cm,right=1.5cm,top=2cm,bottom=3cm]{geometry}
 
\usepackage[headsepline=0.25pt,footsepline=0.25pt]{scrlayer-scrpage}
\pagestyle{scrheadings}
 
\svnidlong{$HeadURL: svn://192.168.0.80/Dokumente/Uwe/Main.tex $}
{$LastChangedDate: 2020-07-16 10:42:03 +0200 (Do, 16 Jul 2020) $}
{$LastChangedRevision: 62 $}
{$LastChangedBy: uwe $}
 
\title{Main Document}
\author{Max Mustermann}
 
\begin{document}
 
\tableofcontents
 
\include{sub-01}
\include{sub-02}
 
\end{document}

Die Subdokumente sehen jeweils wie folgt aus. Über die *foot und *head Befehle werden die Seitenköpfe und -füße mit den Komponenten aus dem Dateinamen befüllt, \addsec fügt die Dokumente zum Inhaltsverzeichnis hinzu.

%!TeX root=main.tex
 
\svnidlong
{$HeadURL: svn://192.168.0.42/Dokumente/Uwe/Sub-01.tex $}
{$LastChangedDate: 2020-07-16 10:10:19 +0200 (Do, 16 Jul 2020) $}
{$LastChangedRevision: 60 $}
{$LastChangedBy: uwe $}
 
\setcounter{page}{1}
 
\ohead{V\svnfilerev\ vom \svnfileday.\svnfilemonth.\svnfileyear}
\ofoot[\gettwofromcurrfilename-\pagemark]{\gettwofromcurrfilename-\pagemark}
\ifoot[\currfilename]{\currfilename} % inner foot
\ihead[]{} % inner head
\cfoot[]{} % center foot
\chead[]{} % center head
 
 
\addsec{\gettwofromcurrfilename~\getonefromcurrfilename}
 
 
\blindtext[6]

Beispieldokument: Main.pdf

Uwe

Uwe Ziegenhagen likes LaTeX and Python, sometimes even combined. Do you like my content and would like to thank me for it? Consider making a small donation to my local fablab, the Dingfabrik Köln. Details on how to donate can be found here Spenden für die Dingfabrik.

More Posts - Website

Mehrsprachige Beamerfolien erstellen – Teil 2

Basierend auf dem letzten Blog-Artikel dazu und einer Frage, die ich 2014 auf TSX gestellt habe, habe ich den Code für mehrsprachige Beamer-Folien angepasst.

\documentclass[ngerman]{beamer}
 
\usepackage{comment}
\makeatletter
\newif\if@ngerman
\newif\if@option@ngerman
\DeclareOption{ngerman}{%
	\@ngermantrue
	\@option@ngermantrue
}
\ProcessOptions*\relax
\newcommand*{\ifngerman}{%
	\if@ngerman
	\expandafter\@firstoftwo
	\else
	\expandafter\@secondoftwo
	\fi
}
\makeatother
 
\ifngerman{
\usepackage[main=ngerman]{babel}
\includecomment{DE}
\excludecomment{EN}
}{
\usepackage[main=english]{babel}
\includecomment{EN}
\excludecomment{DE}
}
 
\begin{document}
	\begin{DE}
		\begin{frame}[fragile]{Hallo Welt}
		Hallo Welt
	\end{frame}
\end{DE}
 
\begin{EN}
	\begin{frame}[fragile]{Hello World}
	Hello World
\end{frame}
\end{EN}
 
\end{document}

Uwe

Uwe Ziegenhagen likes LaTeX and Python, sometimes even combined. Do you like my content and would like to thank me for it? Consider making a small donation to my local fablab, the Dingfabrik Köln. Details on how to donate can be found here Spenden für die Dingfabrik.

More Posts - Website

Mehrsprachige Beamer-Folien erstellen

Unter https://tex.stackexchange.com/questions/443714/bilingual-slides-beamer-comment-package-and-non-ascii-characters-umlauts-dia gibt es ein gutes Beispiel, wie man mehrsprachige Beamer-Folien erstellen kann. Je nach gesetztem \newcommand{\lvlang}{EN} wird entweder die englische oder deutsche Version erzeugt.

Der Code müsste sich noch verbessern lassen, wenn man beispielsweise globale Klassenoptionen wie english oder ngerman auswertet. Nachtrag: Siehe dazu https://www.uweziegenhagen.de/?p=4352

Hier ein vollständiges Beispiel:

\documentclass{beamer}
 
\newcommand{\lvlang}{EN}
 
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
 
\usepackage{comment}
\long\def\WriteCommentLine#1{\immediate\write\CommentStream{\unexpanded{#1}}}
\let\ThisComment\WriteCommentLine
 
\usepackage{ifthen}
\newcommand{\iflvlangde}[2]{%
  \ifthenelse{\equal{\lvlang}{DE}}{#1}{#2}%
}
 
\makeatletter
\iflvlangde{
  \usepackage[main=ngerman]{babel}
  \includecomment{DE}
  \excludecomment{EN}
}{
  \usepackage[main=english]{babel}
  \includecomment{EN}
  \excludecomment{DE}
}
\makeatother
 
\begin{document}
\begin{DE}
\begin{frame}[fragile]{Hallo Welt}
  Hallo Welt
\end{frame}
\end{DE}
 
\begin{EN}
\begin{frame}[fragile]{Hello World}
  Hello World
\end{frame}
\end{EN}
 
\end{document}

Uwe

Uwe Ziegenhagen likes LaTeX and Python, sometimes even combined. Do you like my content and would like to thank me for it? Consider making a small donation to my local fablab, the Dingfabrik Köln. Details on how to donate can be found here Spenden für die Dingfabrik.

More Posts - Website

Beamer-Vorlage für (MINT)-Vorlesungen

Ich habe heute die erste Version einer Beamer-Vorlage für Vorlesungen auf github hochgeladen. Ziel war es, sowohl einzelne Module (Vorlesungen) als auch den kompletten Foliensatz erzeugen zu können. Die Vorlage eignet sich nicht nur für MINT-Veranstaltungen, mein Fokus lag aber auf dem sauberen Einbinden von Quellcodes, was bei geisteswissenschaftlichen Vorlesungen vielleicht nicht der Hauptfokus ist.

Die Dateien finden sich unter https://github.com/UweZiegenhagen/MINT-Lecture-Slide-Template

Pull Requests, Kommentare und Vorschläge werden gern gesehen.

Als nächstes baue ich noch Beispiele für die von mir definierten Befehle ein, die ein vereinfachtes Einbetten von Grafiken und Quellcodes erlauben.

Uwe

Uwe Ziegenhagen likes LaTeX and Python, sometimes even combined. Do you like my content and would like to thank me for it? Consider making a small donation to my local fablab, the Dingfabrik Köln. Details on how to donate can be found here Spenden für die Dingfabrik.

More Posts - Website

Monatskalender für LaTeX mit Python erzeugen

Hier ein Beispiel, wie man mit Python kleine Monatskalender erzeugen kann. Geht auch mit LaTeX allein, ich möchte aber verschiedene Output-Formate (Markdown, HTML, etc.) erzeugen und dabei die komplette Kontrolle über den Code behalten.

# -*- coding: utf-8 -*-
 
import calendar
import datetime
 
def number_of_weeks(year, month):
    """
        Returns a tupel with the ISO no of the first and week and the no of weeks
    """
    tup_month_days = calendar.monthrange(year, month)
    first = datetime.date(year, month, 1)
    last = datetime.date(year, month, tup_month_days[1])
    first_week = first.isocalendar()[1]
    last_week = last.isocalendar()[1]
    return (first_week, last_week, last_week-first_week+1)
 
def gen_cal_latex(year, month):
    """
        https://stackoverflow.com/questions/9459337/assign-value-to-an-individual-cell-in-a-two-dimensional-python-array
    """
    c = calendar.TextCalendar()
    week_month_first, week_month_last, no_of_weeks = number_of_weeks(year, month)
 
    # generate calendar list, using tupel as a key    
    m = {(i, j):' ' for i in range(no_of_weeks) for j in range(7)}
 
    for tupel_date in c.itermonthdays4(year, month):
        t_year, t_month, t_day, t_weekday = tupel_date
        # use only dates inside the required month
        if t_month == month:
            temp_date = datetime.date(t_year, t_month, t_day)
            # check in which week we are with the current date
            # to get index for the list
            week_no = temp_date.isocalendar()[1]
            m[week_no % week_month_first, t_weekday] = t_day
 
    print(r'\begin{tabular}{rrrrrrr}')
    print(r'Mo & Di & Mi & Do & Fr & Sa & So \\')
    for i in m:
        if i[1] < 6:
            print('{0} &'.format(m[i]), end='')
        else:
            print('{0}'.format(m[i]),end='')
        if i[1] == 6:
            print(r'\\')
    print(r'\end{tabular}')
 
gen_cal_latex(2020, 4)

Erzeugt werden kleine Monatskalender der Form

\begin{tabular}{rrrrrrr}
Mo & Di & Mi & Do & Fr & Sa & So \\
  &  &1 &2 &3 &4 &5\\
6 &7 &8 &9 &10 &11 &12\\
13 &14 &15 &16 &17 &18 &19\\
20 &21 &22 &23 &24 &25 &26\\
27 &28 &29 &30 &  &  & \\
\end{tabular}

Per Copy & Paste kann man den Code in ein LaTeX-Dokument kopieren, natürlich lässt sich das alles auch direkt in eine LaTeX-Datei schreiben.

Uwe

Uwe Ziegenhagen likes LaTeX and Python, sometimes even combined. Do you like my content and would like to thank me for it? Consider making a small donation to my local fablab, the Dingfabrik Köln. Details on how to donate can be found here Spenden für die Dingfabrik.

More Posts - Website

Trello-Boards exportieren mit py-trello

Hier etwas Beispiel-Code, um Trello-Boards zu exportieren. Unten im Code nur nach stdout, Code für LaTeX und HTML/MD werde ich im Github Repository https://github.com/UweZiegenhagen/python-trello-output ergänzen.

from trello import TrelloClient # pip install py-trello
 
client = TrelloClient(
    api_key='<secret_api_key>',
    token='<secret_token>'
)
 
def list_all_boards(client):
    """
        get list of all boards to determine the ID
        for further functions
    """
    all_boards = client.list_boards()
    for counter, board in enumerate(all_boards):
        print(counter, board.name)
 
## uncomment if needed
# list_all_boards(client)
 
def print_cards_from_board(board_id, client):
    """
        Access board with ID board_id in the client instance
        and print all non-archived lists with their non-archived cards 
    """
    all_boards = client.list_boards()
    my_board = all_boards[board_id] # 15 = my someday projects
    all_lists_on_board = my_board.list_lists()
 
    for list in all_lists_on_board:
        if not list.closed:
            for card in list.list_cards():
                if not card.closed:
                    print(list.name, ':' , card.name)
 
print_cards_from_board(15, client)

Uwe

Uwe Ziegenhagen likes LaTeX and Python, sometimes even combined. Do you like my content and would like to thank me for it? Consider making a small donation to my local fablab, the Dingfabrik Köln. Details on how to donate can be found here Spenden für die Dingfabrik.

More Posts - Website