From 9f498a7c61b730021ed4006568c734cabad50929 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Ke=C3=9Fler?= Date: Fri, 17 Sep 2021 09:32:41 +0200 Subject: [PATCH] add config parameter for indentation --- scripts/config.py | 1 + scripts/notes.py | 6 +++--- scripts/parse_counters.py | 8 +++----- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/scripts/config.py b/scripts/config.py index e1eb48b..5768ac7 100644 --- a/scripts/config.py +++ b/scripts/config.py @@ -21,3 +21,4 @@ LECTURE_START_MARKER = 'start lectures' LECTURE_END_MARKER = 'end lectures' DEFAULT_NEW_LECTURE_HEADER = r'\lecture{{{number}}}{{{date}}}{{{title}}}' DEFAULT_LECTURE_SEARCH_REGEX = r'lecture{(.*?)}{(.*?)}{(.*)}' +DEFAULT_IMPORT_INDENTATION = 4 diff --git a/scripts/notes.py b/scripts/notes.py index 0c02569..a55e257 100644 --- a/scripts/notes.py +++ b/scripts/notes.py @@ -3,7 +3,7 @@ import subprocess from pathlib import Path 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 @@ -63,12 +63,12 @@ class Notes: input_command = r'\input{' else: 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): if not setcounters: 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 '' diff --git a/scripts/parse_counters.py b/scripts/parse_counters.py index f7e20ab..01a7ce6 100755 --- a/scripts/parse_counters.py +++ b/scripts/parse_counters.py @@ -2,6 +2,7 @@ import re from pathlib import Path from typing import Dict +from config import DEFAULT_IMPORT_INDENTATION 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): 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) - - -# print(dict2setcounters(parse_counters(Path('~/Uni/semester-5/topologie-1/notes/master.counters').expanduser(), -# {'exercise': 5}))) + return ''.join(' ' * DEFAULT_IMPORT_INDENTATION + r'\setcounter{' + counter + '}{' + str(num) + '}\n' + for (counter, num) in counters_as_list)