99 lines
3 KiB
Python
99 lines
3 KiB
Python
from .macros import *
|
|
from .enums import TeXFlavour, Argument
|
|
|
|
|
|
def make_simple_macro(name: str, arg):
|
|
return SimpleMacro(
|
|
name,
|
|
MacroReplacement(
|
|
'%s',
|
|
arg
|
|
)
|
|
)
|
|
|
|
|
|
def get_default_macros(tex_flavour: TeXFlavour):
|
|
both = [
|
|
make_simple_macro('!', FormatterProperty.file_prefix),
|
|
make_simple_macro('name', FormatterProperty.name),
|
|
make_simple_macro('author', FormatterProperty.author),
|
|
make_simple_macro('date', FormatterProperty.date),
|
|
make_simple_macro('year', FormatterProperty.year),
|
|
make_simple_macro('shortauthor', FormatterProperty.shortauthor),
|
|
make_simple_macro('version', FormatterProperty.version),
|
|
make_simple_macro('filename', FormatterProperty.file_name),
|
|
make_simple_macro('prefix', FormatterProperty.file_prefix),
|
|
make_simple_macro('repoversion', FormatterProperty.repo_version),
|
|
make_simple_macro('repobranch', FormatterProperty.repo_branch),
|
|
make_simple_macro('repocommit', FormatterProperty.repo_commit),
|
|
make_simple_macro('repodirty', FormatterProperty.repo_dirty),
|
|
make_simple_macro('sourcename', FormatterProperty.source_file_name),
|
|
ConfigEndMacro(),
|
|
ConfigBeginMacro()
|
|
]
|
|
tex2 = [
|
|
ArgumentMacro(
|
|
'newif',
|
|
2,
|
|
MacroReplacement(
|
|
r'\newif\if%s@%s\%s@%s%s',
|
|
FormatterProperty.file_prefix,
|
|
Argument.one,
|
|
FormatterProperty.file_prefix,
|
|
Argument.one,
|
|
Argument.two
|
|
)
|
|
),
|
|
ArgumentMacro(
|
|
'setif',
|
|
2,
|
|
MacroReplacement(
|
|
r'\%s@%s%s',
|
|
FormatterProperty.file_prefix,
|
|
Argument.one,
|
|
Argument.two
|
|
)
|
|
),
|
|
ArgumentMacro(
|
|
'if',
|
|
1,
|
|
MacroReplacement(
|
|
r'\if%s@%s',
|
|
FormatterProperty.file_prefix,
|
|
Argument.one
|
|
)
|
|
),
|
|
ArgumentMacro(
|
|
'header',
|
|
1,
|
|
MacroReplacement(
|
|
r'\Provides%s{%s}[%s - %s (%s)]',
|
|
FormatterProperty.Tex_type,
|
|
FormatterProperty.name,
|
|
FormatterProperty.date,
|
|
Argument.one,
|
|
FormatterProperty.version
|
|
)
|
|
)
|
|
]
|
|
|
|
tex3 = [
|
|
ArgumentMacro(
|
|
'header',
|
|
1,
|
|
MacroReplacement(
|
|
'\\ProvidesExpl%s { %s } { %s } { %s }\n { %s }',
|
|
FormatterProperty.Tex_type,
|
|
FormatterProperty.name,
|
|
FormatterProperty.date,
|
|
FormatterProperty.version,
|
|
FormatterProperty.description
|
|
)
|
|
)
|
|
]
|
|
if tex_flavour == TeXFlavour.LaTeX2e:
|
|
return tex2 + both
|
|
elif tex_flavour == TeXFlavour.LaTeX3:
|
|
return tex3 + both
|
|
else:
|
|
raise NotImplementedError
|