add class formatting support. add script class

This commit is contained in:
Maximilian Keßler 2021-10-08 16:35:32 +02:00
parent 8bf21475c5
commit d694677d73
3 changed files with 39 additions and 38 deletions

2
PyTeX

@ -1 +1 @@
Subproject commit dbdd99cc3d6e02b0cfadb1d337f6b85c5f52a9b5
Subproject commit 6c0dee2511b1e28a8af3ceefa2219fc5135c8221

View File

@ -6,7 +6,7 @@ from datetime import *
sys.path.insert(0, 'PyTeX/')
from package_formatter import PackageFormatter
from replacements import make_default_commands
from class_formatter import ClassFormatter
from git_version import git_describe, get_latest_commit
BUILD_DETAILS = [
@ -41,14 +41,21 @@ def build(build_dir: str):
if git.Repo().is_dirty():
extra_header += ['WARNING: Local changes to git repository detected.',
' The build will not be reproducible (!)']
num_files = 0
num_packages = 0
num_classes = 0
for file in input_root.rglob('*.pysty'):
num_files += 1
num_packages += 1
formatter = PackageFormatter(package_name=file.with_suffix('').name, extra_header=extra_header)
print('[PyTeX] Writing file {}'.format(formatter.file_name))
make_default_commands(formatter)
formatter.format_package(file, Path('./').resolve() / build_dir / str(file.parent.relative_to(input_root)))
print(f'[PyTeX] Successfully built {num_files} packages in {build_dir}/')
formatter.make_default_macros()
formatter.format_file(file, Path('./').resolve() / build_dir / str(file.parent.relative_to(input_root)))
for file in input_root.rglob('*.pycls'):
num_classes += 1
formatter = ClassFormatter(class_name=file.with_suffix('').name, extra_header=extra_header)
print('[PyTeX] Writing class file {}'.format(formatter.file_name))
formatter.make_default_macros()
formatter.format_file(file, Path('./').resolve() / build_dir / str(file.parent.relative_to(input_root)))
print(f'[PyTeX] Successfully built {num_packages} packages and {num_classes} classes in {build_dir}/')
if __name__ == "__main__":

View File

@ -1,55 +1,49 @@
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{mkessler-script}[2021/03/31 Write up lecture notes as script]
__HEADER__(Write up lecture notes as script)
%%%%Options of the package
\newif\ifenglish\englishtrue
\DeclareOption{english}{\englishtrue}
\DeclareOption{german}{\englishfalse}
__LANGUAGE_OPTIONS__
\newif\ifshowversion\showversiontrue
\DeclareOption{show version}{\showversiontrue}
\DeclareOption{hideversion}{\showversionfalse}
__NEW_IF__(showversion,true)
\DeclareOption{show version}{__SET_IF__(showversion,true)}
\DeclareOption{hideversion}{__SET_IF__(showversion,false)}
\newif\iffancyfoot\fancyfootfalse
\DeclareOption{fancyfoot}{\fancyfoottrue}
\newif\ifgitversion\gitversionfalse
\DeclareOption{git}{\gitversiontrue}
\ProcessOptions\relax
__NEW_IF__(fancyfoot,false)
\DeclareOption{fancyfoot}{__SET_IF__(fancyfoot,true)}
__NEW_IF__(gitversion,false)
\DeclareOption{git}{__SET_IF__(gitversion,true)}
__END_OPTIONS__
\RequirePackage{xifthen}
%%%%Define command to set metainformation of document
%Set the course
\def\@course{\ClassError{mkessler-script}{No \noexpand\course given}{See documentation for details}}%
\def\@course{__ERROR__(No \noexpand\course given){See documentation for details}}%
\DeclareRobustCommand*{\course}[1]{\gdef\@course{#1}}
\def\@lecturer{\ClassError{mkessler-script}{No \noexpand\lecturer given}{See documentation for details}}%
\def\@lecturer{__ERROR__(No \noexpand\lecturer given){See documentation for details}}%
\def\@lecturertitle{}
\DeclareRobustCommand*{\lecturer}[2][]{
\gdef\@lecturer{#2}
\gdef\@lecturertitle{\ifenglish Lecturer\else\ifthenelse{\isempty{#1}}{Dozent}{Dozentin}\fi}{}
\gdef\@lecturertitle{__IF__(english) Lecturer\else\ifthenelse{\isempty{#1}}{Dozent}{Dozentin}\fi}{}
}
%Set the assistant
\newif\ifprintassistant\printassistantfalse
__NEW_IF__(printassistant,false)
\def\@assistant{}%
\def\@assistantitle{}
\DeclareRobustCommand*{\assistant}[2][]{
\printassistanttrue
__SET_IF__(printassistant,true)
\gdef\@assistant{#2}
\gdef\@assistanttitle{\ifenglish Assistant\else\ifthenelse{\isempty{#1}}{Assistent}{Assistentin}\fi}
\gdef\@assistanttitle{__IF__(english) Assistant\else\ifthenelse{\isempty{#1}}{Assistent}{Assistentin}\fi}
}
%%%%Load base class article
\LoadClass{article}
\ifshowversion
\ifgitversion
__IF__(showversion)
__IF__(gitversion)
\RequirePackage[dirty={ (local changes have been made!)}]{gitinfo2}
\fi
\fi
@ -73,7 +67,7 @@
\@lecturertitle \\
{\sc \@lecturer} \\
\end{tabular}\par
\ifprintassistant
__IF__(printassistant)
\vskip 1em%
\begin{tabular}[t]{c}%
\@assistanttitle \\
@ -82,17 +76,17 @@
\fi
\vskip 1em%
\begin{tabular}[t]{c}%
\ifenglish Notes\else Mitschrift\fi \\
__IF__(english) Notes\else Mitschrift\fi \\
{\sc \@author} \\
\end{tabular}
\par}%
\ifshowversion
__IF__(showversion)
\vskip 3em%
\begin{tabular}[t]{c}%
{\small Version} \\
\ifgitversion
__IF__(gitversion)
git: \gitFirstTagDescribe\\
\ifenglish compiled\else kompiliert\fi:
__IF__(english) compiled\else kompiliert\fi:
\fi\today\,\currenttime \\
\end{tabular}\par
\fi
@ -131,7 +125,7 @@
%%%% These are the fancy headers
\iffancyfoot
__IF__(fancyfoot)
\RequirePackage{fancyhdr}
\pagestyle{fancy}