Exemple #1
0
    def __init__(self, config_file):
        with open(config_file, 'r') as file:
            try:
                self.config = yaml.safe_load(file)
            except yaml.YAMLError as err:
                print(err)

        self.floats = []
        if 'floats' in self.config:
            for floatOpt in self.config['floats']:
                for opt, val in floatOpt.items():
                    if len(val) > 0 and val != 'default':
                        self.floats += [LatexLengthOption(opt, val)]

        self.compact_items = False
        self.compact_enums = False
        if 'lists' in self.config:
            list_config = self.config['lists']
            if 'compact-items' in list_config:
                self.compact_items = list_config['compact-items']
            if 'compact-enums' in list_config:
                self.compact_enums = list_config['compact-enums']

        self.headings = []
        if 'headings' in self.config:
            heads_config = self.config['headings']
            for head in heads_config:
                head_config = heads_config[head]
                left = head_config['left'] or "0pt"
                above = head_config['above'] or "0pt"
                below = head_config['below'] or "0pt"
                self.headings += [
                    LatexCommand('titlespacing', None,
                                 [f'\\{head}', left, above, below])
                ]

        self.paragraphs = []
        if 'paragraphs' in self.config:
            for opt, val in self.config['paragraphs'].items():
                if len(val) > 0 and val != 'default':
                    self.paragraphs += [LatexLengthOption(opt, val)]

        self.equations = []
        if 'equations' in self.config:
            for opt, val in self.config['equations'].items():
                if len(val) > 0 and val != 'default':
                    self.equations += [LatexLengthOption(opt, val)]

        spread_factor = 1.0
        if 'line-spread' in self.config:
            spread_factor = self.config['line-spread']
        self.line_spread = [LatexCommand('linespread', [], str(spread_factor))]

        self.caption_opts = []
        if 'captions' in self.config:
            if 'above-skip' in self.config['captions']:
                aboveskip = self.config['captions']['above-skip']
                if aboveskip != 'default':
                    self.caption_opts += [f'above-skip={aboveskip}']
            if 'below-skip' in self.config['captions']:
                belowskip = self.config['captions']['below-skip']
                if belowskip != 'default':
                    self.caption_opts += [f'below-skip={belowskip}']
            if 'skip' in self.config['captions']:
                skip = self.config['captions']['skip']
                if skip != 'default':
                    self.caption_opts += [f'skip={skip}']
            if 'font' in self.config['captions']:
                font = self.config['captions']['font']
                if font != 'default':
                    self.caption_opts += [f'font={font}']