2021-10-06 17:08:53 +02:00
|
|
|
from enums import Attributes, Args
|
2021-10-08 16:12:48 +02:00
|
|
|
from formatter import Formatter
|
2021-10-07 08:58:43 +02:00
|
|
|
from config import LICENSE, PACKAGE_INFO_TEXT, PYTEX_INFO_TEXT
|
2021-10-06 17:08:53 +02:00
|
|
|
|
|
|
|
|
2021-10-08 16:12:48 +02:00
|
|
|
def make_default_commands(formatter: Formatter, latex_file_type: str):
|
2021-10-07 08:58:43 +02:00
|
|
|
header = '%' * 80 + '\n' \
|
2021-10-07 18:00:41 +02:00
|
|
|
+ '\n'.join(map(lambda line: '% ' + line,
|
|
|
|
LICENSE + [''] + PACKAGE_INFO_TEXT + [''] + PYTEX_INFO_TEXT
|
2021-10-08 16:12:48 +02:00
|
|
|
+ [''] + formatter.extra_header)
|
2021-10-07 18:00:41 +02:00
|
|
|
) \
|
2021-10-07 08:58:43 +02:00
|
|
|
+ '\n' + '%' * 80 + '\n\n' \
|
2021-10-06 22:59:00 +02:00
|
|
|
+ '\\NeedsTeXFormat{{LaTeX2e}}\n' \
|
2021-10-08 16:12:48 +02:00
|
|
|
'\\Provides{Type}{{{name_lowercase}}}[{date} - {description}]\n\n'
|
|
|
|
formatter.add_arg_replacement(
|
2021-10-06 18:23:41 +02:00
|
|
|
1, 'header',
|
|
|
|
header,
|
2021-10-08 16:12:48 +02:00
|
|
|
name_lowercase=Attributes.name_lowercase,
|
2021-10-06 18:23:41 +02:00
|
|
|
date=Attributes.date,
|
|
|
|
description=Args.one,
|
|
|
|
year=Attributes.year,
|
2021-10-07 08:58:43 +02:00
|
|
|
copyright_holders=Attributes.author,
|
2021-10-08 16:12:48 +02:00
|
|
|
source_file=Attributes.source_file_name,
|
|
|
|
Type=latex_file_type.capitalize(),
|
|
|
|
latex_file_type=latex_file_type
|
2021-10-06 18:23:41 +02:00
|
|
|
)
|
2021-10-08 16:12:48 +02:00
|
|
|
formatter.add_replacement('{Type} name'.format(Type=latex_file_type), '{}', Attributes.name_lowercase)
|
|
|
|
formatter.add_replacement('{Type} prefix'.format(Type=latex_file_type), '{}', Attributes.prefix)
|
|
|
|
formatter.add_arg_replacement(1, '{Type} macro'.format(Type=latex_file_type), r'\{}{}', Attributes.prefix, Args.one)
|
|
|
|
formatter.add_replacement('file name', '{name}', name=Attributes.file_name)
|
|
|
|
formatter.add_replacement('date', '{}', Attributes.date)
|
|
|
|
formatter.add_replacement('author', '{}', Attributes.author)
|
|
|
|
formatter.add_arg_replacement(2, 'new if', r'\newif\if{prefix}{condition}\{prefix}{condition}{value}',
|
|
|
|
prefix=Attributes.prefix, condition=Args.one, value=Args.two)
|
|
|
|
formatter.add_arg_replacement(2, 'set if', r'\{prefix}{condition}{value}',
|
|
|
|
prefix=Attributes.prefix, condition=Args.one, value=Args.two)
|
|
|
|
formatter.add_arg_replacement(1, 'if', r'\if{prefix}{condition}', prefix=Attributes.prefix,
|
|
|
|
condition=Args.one)
|
|
|
|
formatter.add_replacement('language options x',
|
2021-10-06 22:59:00 +02:00
|
|
|
r'\newif\if{prefix}english\{prefix}englishtrue' + '\n' +
|
|
|
|
r'\DeclareOptionX{{german}}{{\{prefix}englishfalse}}' + '\n' +
|
|
|
|
r'\DeclareOptionX{{ngerman}}{{\{prefix}englishfalse}}' + '\n' +
|
|
|
|
r'\DeclareOptionX{{english}}{{\{prefix}englishtrue}}',
|
2021-10-08 16:12:48 +02:00
|
|
|
prefix=Attributes.prefix)
|
|
|
|
formatter.add_replacement('language options',
|
2021-10-07 13:52:20 +02:00
|
|
|
r'\newif\if{prefix}english\{prefix}englishtrue' + '\n' +
|
|
|
|
r'\DeclareOption{{german}}{{\{prefix}englishfalse}}' + '\n' +
|
|
|
|
r'\DeclareOption{{ngerman}}{{\{prefix}englishfalse}}' + '\n' +
|
|
|
|
r'\DeclareOption{{english}}{{\{prefix}englishtrue}}',
|
2021-10-08 16:12:48 +02:00
|
|
|
prefix=Attributes.prefix)
|
|
|
|
formatter.add_arg_replacement(1, 'info', r'\{Type}Info{{{name}}}{{{info}}}', name=Attributes.name_lowercase,
|
|
|
|
info=Args.one, Type=latex_file_type.capitalize())
|
|
|
|
formatter.add_arg_replacement(1, 'warning', r'\{Type}Warning{{{name}}}{{{warning}}}',
|
|
|
|
name=Attributes.name_lowercase, warning=Args.one, Type=latex_file_type.capitalize())
|
2021-10-08 16:34:52 +02:00
|
|
|
formatter.add_arg_replacement(1, 'error', r'\{Type}Error{{{name}}}{{{error}}}',
|
2021-10-08 16:12:48 +02:00
|
|
|
name=Attributes.name_lowercase, error=Args.one, Type=latex_file_type.capitalize())
|
|
|
|
formatter.add_replacement('end options x',
|
|
|
|
r"\DeclareOptionX*{{\{Type}Warning{{{name_lowercase}}}"
|
2021-10-08 20:01:23 +02:00
|
|
|
r"{{Unknown '\CurrentOption'}}}}" + '\n' + r'\ProcessOptionsX*\relax' + '\n',
|
2021-10-08 16:12:48 +02:00
|
|
|
name_lowercase=Attributes.name_lowercase, Type=latex_file_type.capitalize())
|
|
|
|
formatter.add_replacement('end options',
|
|
|
|
r"\DeclareOption*{{\{Type}Warning{{{name_lowercase}}}"
|
2021-10-06 22:59:00 +02:00
|
|
|
r"{{Unknown '\CurrentOption'}}}}" + '\n' + r'\ProcessOptions\relax' + '\n',
|
2021-10-08 16:12:48 +02:00
|
|
|
name_lowercase=Attributes.name_lowercase, Type=latex_file_type.capitalize())
|