示例#1
0
    def write_tex(self, output):
        """Build the '.tex' file corresponding to self.

        Arguments:
        - output: a file object, in which the file will be written.
        """
        # Updating configuration
        self._config = self._raw_config.copy()
        renderer = TexBookRenderer(
            self._config['book']['template'],
            self._config['_datadir'],
            self._config['book']['lang'],
            self._config['book']['encoding'],
        )

        try:
            self._config['_template'] = renderer.get_all_variables(
                self._config.get('template', {}))
        except errors.SchemaError as exception:
            exception.message = "The songbook file '{}' is not valid\n{}".format(
                self.basename, exception.message)
            raise exception

        self._config['_compiled_authwords'] = authors.compile_authwords(
            copy.deepcopy(self._config['authors']))

        # Configuration set
        self._config['render'] = content.render
        self._config['content'] = content.process_content(
            self._config.get('content', []),
            self._config,
        )
        self._config['filename'] = output.name[:-4]

        # Processing special options
        self._config['_bookoptions'] = iter_bookoptions(self._config)
        self._config['chords']['_notenames'] = self._get_chord_names(
            self._config['chords']['notation'])

        renderer.render_tex(output, self._config)

        # Get all errors, and maybe exit program
        self._errors.extend(renderer.errors)
        if self._config['_error'] == "failonbook":
            if self.has_errors():
                raise errors.SongbookError(
                    "Some songs contain errors. Stopping as requested.")