zephyr/doc/scripts/fix_tex.py
Daniel Leung 9945e7fda0 doc: add ability to generate PDF
This adds new targets to generate build documentation through
LaTEX to PDF.

There are a few notes:

1. pdflatex complains about the tex file generated by doxygen
   so it needs to be fixed with a Python script before feeding
   in through pdflatex.

2. SVG files are not recognized by pdflatex so they are converted
   to known good format on the fly, only for producing PDF. This
   uses the libRSVG's rsvg-convert tool.

Relates to #6782.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2018-08-29 18:16:56 -04:00

45 lines
994 B
Python

#!/usr/bin/env python3
#
# Copyright (c) 2018, Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0
# Fix the .tex file produced by doxygen
# before feeding to pdflatex or latexmk.
import argparse
import re
def regex_replace(tex_file):
patterns = [
# runaway argument
("}}\r?\n=\r?\n\r?\n\t{6}", "}} = ")
]
f = open(tex_file, mode='r', encoding="utf-8")
content = f.read()
f.close()
for p in patterns:
content = re.sub(p[0], p[1], content)
f = open(tex_file, mode='w', encoding="utf-8")
f.write(content)
f.close()
return
def main():
parser = argparse.ArgumentParser(description='Fix the .tex file produced '
'by doxygen before feeding it to '
'latexmk (or pdflatex).')
parser.add_argument('tex_file', nargs=1)
args = parser.parse_args()
regex_replace(args.tex_file[0])
if __name__ == "__main__":
main()