Welcome to pandocwrapper's documentation!¶
pandocwrapper¶
-
class
pandocwrapper.
BaseConverter
(file_in, file_out=None, from_format=None, to_format=None, path_to_files='.', verbose=False)¶ Base Converter
Class to convert from and to different formats, default is to convert to PDF.
-
add_arguments
(*to_add)¶ Adds argument to list of arguments(
self.arguments
), that will be executed as a command in a subprocessParameters: to_add (str or list of str) -- argument(s) to add to the argument list Returns: nothing
-
construct_command
()¶ Constructs the base command, based on the class attributes.
Always starts with
pandoc
. Second is-f
ifself.from_format
given. Third is-t
if given and matching theself.file_out
ending, otherwise changesself.file_out
ending to .pdf and setsself.to_format
toNone
. Last is the--verbose
flag ifself.verbose
isTrue
.Returns: nothing
-
convert
()¶ Converts the input file by sending the pandoc command to a subprocess.
- First adds missing, but common arguments to the arguments list:
--pdf-engine
(ifself.to_format
isNone
)-o self.file_out
self.file_in
Creates a subprocess using Popen,
self.arguments
is set asargs
of the subprocess. Sets the working directory (cwd
) toself.path_to_files
.Prints stdout and error (if happened) of subprocess to console.
Returns: nothing
-
-
class
pandocwrapper.
DocxConverter
(file_in, file_out=None, template=None, from_format='docx', to_format=None, path_to_files='.', verbose=False)¶ Docx Converter
Converts from docx to different formats, default is to convert to PDF.
-
construct_command
()¶ Calls
BaseConverter.construct_command()
first.Sets
self.template
to htwberlin.tex, ifself.template
is not None. Adds-s
,--data-dir=.
toself.arguments
.--data-dir
is set to the current directory because the working directory of the subprocess will be set toself.path_to_files
. Adds--template=self.template
ifself.to_format
is None, so output will be pdf. Or adds--reference=self.template
ifself.to_format
is docx andself.template
ends in .docxReturns: nothing
-
-
class
pandocwrapper.
LatexConverter
(file_in, file_out=None, bib=None, template=None, resources_path=None, from_format='latex', to_format=None, path_to_files='.', verbose=False)¶ Latex Converter
Converts from latex to different formats, default is to convert to PDF.
-
construct_command
()¶ Calls
BaseConverter.construct_command()
first.Sets
self.template
to htwberlin.tex, ifself.template
is not None. Adds--bibliography=self.bib
(ifself.bib
is notNone
) toself.arguments
. Adds-s
,--data-dir=.
and--template=self.template
toself.arguments
.--data-dir
is set to the current directory because the working directory of the subprocess will be set toself.path_to_files
.Returns: nothing
-
-
class
pandocwrapper.
MdConverter
(file_in, file_out=None, template=None, from_format='markdown', path_to_files='.', verbose=False, toc=False)¶ Markdown Converter
Converts from markdown to PDF using beamer
-
construct_command
()¶ Calls
BaseConverter.construct_command()
first.Sets
self.template
to htwberlin-beamer.tex, ifself.template
is not None. Adds-s
,--data-dir=.
toself.arguments
.--data-dir
is set to the current directory because the working directory of the subprocess will be set toself.path_to_files
. Adds -t beamer!Returns: nothing
-
-
class
pandocwrapper.
OdtConverter
(file_in, file_out=None, template=None, from_format='odt', to_format=None, path_to_files='.', verbose=False)¶ Odt Converter
Converts from odt to different formats, default is to convert to PDF.
-
construct_command
()¶ Calls
BaseConverter.construct_command()
first.Sets
self.template
to htwberlin.tex, ifself.template
is not None. Adds-s
,--data-dir=.
toself.arguments
.--data-dir
is set to the current directory because the working directory of the subprocess will be set toself.path_to_files
. Adds--template=self.template
ifself.to_format
is None, so output will be pdf. Or adds--reference=self.template
ifself.to_format
is odt andself.template
ends in .odtReturns: nothing
-