add config parameter for indentation

This commit is contained in:
Maximilian Keßler 2021-09-17 09:32:41 +02:00
parent 1b82dfd627
commit 9f498a7c61
3 changed files with 7 additions and 8 deletions

View File

@ -21,3 +21,4 @@ LECTURE_START_MARKER = 'start lectures'
LECTURE_END_MARKER = 'end lectures' LECTURE_END_MARKER = 'end lectures'
DEFAULT_NEW_LECTURE_HEADER = r'\lecture{{{number}}}{{{date}}}{{{title}}}' DEFAULT_NEW_LECTURE_HEADER = r'\lecture{{{number}}}{{{date}}}{{{title}}}'
DEFAULT_LECTURE_SEARCH_REGEX = r'lecture{(.*?)}{(.*?)}{(.*)}' DEFAULT_LECTURE_SEARCH_REGEX = r'lecture{(.*?)}{(.*?)}{(.*)}'
DEFAULT_IMPORT_INDENTATION = 4

View File

@ -3,7 +3,7 @@ import subprocess
from pathlib import Path from pathlib import Path
from lectures import Lectures, number2filename from lectures import Lectures, number2filename
from config import DEFAULT_MASTER_FILE_NAME, LECTURE_START_MARKER, LECTURE_END_MARKER from config import DEFAULT_MASTER_FILE_NAME, LECTURE_START_MARKER, LECTURE_END_MARKER, DEFAULT_IMPORT_INDENTATION
from parse_counters import parse_counters, dict2setcounters from parse_counters import parse_counters, dict2setcounters
@ -63,12 +63,12 @@ class Notes:
input_command = r'\input{' input_command = r'\input{'
else: else:
input_command = r'\import{' + str(self.lectures.root.relative_to(self.root)) + '/}{' input_command = r'\import{' + str(self.lectures.root.relative_to(self.root)) + '/}{'
return ' ' * 4 + input_command + number2filename(num) + '}\n' return ' ' * DEFAULT_IMPORT_INDENTATION + input_command + number2filename(num) + '}\n'
def set_counters(self, lecture_list, lec, setcounters=False): def set_counters(self, lecture_list, lec, setcounters=False):
if not setcounters: if not setcounters:
return '' return ''
if lec - 1 not in lecture_list: if lec - 1 not in lecture_list and self.full_file:
return dict2setcounters(parse_counters(self.full_file.with_suffix('.counters'), {'lecture': lec})) return dict2setcounters(parse_counters(self.full_file.with_suffix('.counters'), {'lecture': lec}))
return '' return ''

View File

@ -2,6 +2,7 @@
import re import re
from pathlib import Path from pathlib import Path
from typing import Dict from typing import Dict
from config import DEFAULT_IMPORT_INDENTATION
def parse_counters(filepath: Path, break_point: Dict) -> Dict: def parse_counters(filepath: Path, break_point: Dict) -> Dict:
@ -20,8 +21,5 @@ def parse_counters(filepath: Path, break_point: Dict) -> Dict:
def dict2setcounters(counters: Dict): def dict2setcounters(counters: Dict):
counters_as_list = [(counter, counters[counter]) for counter in counters.keys()] counters_as_list = [(counter, counters[counter]) for counter in counters.keys()]
return ''.join(' ' * 4 + r'\setcounter{' + counter + '}{' + str(num) + '}\n' for (counter, num) in counters_as_list) return ''.join(' ' * DEFAULT_IMPORT_INDENTATION + r'\setcounter{' + counter + '}{' + str(num) + '}\n'
for (counter, num) in counters_as_list)
# print(dict2setcounters(parse_counters(Path('~/Uni/semester-5/topologie-1/notes/master.counters').expanduser(),
# {'exercise': 5})))