def test_parser_do_not_concat_text(self): self.parser = LatexParser(self.document, do_not_concat_text=True) assert ( self.parser.getResult().getDocument() == r"""\documentclass[11pt,a4paper,oneside]{report} \usepackage{pslatex,palatino,avant,graphicx,color} \usepackage[margin=2cm]{geometry} % test % test % test % test \begin{document} \title{\color{red}Practical Typesetting} \author{\color{blue}Name} \date{\color{green}December 2005} \maketitle Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam dapibus consectetur tellus. Duis vehicula, tortor gravida sollicitudin eleifend, erat eros feugiat nisl, eget ultricies risus magna ac leo. Ut est diam, faucibus tincidunt ultrices sit amet, congue sed tellus. Donec vel tellus vitae sem mattis congue. Suspendisse faucibus semper faucibus. Curabitur congue est arcu, nec sollicitudin odio blandit at. Nullam tempus vulputate aliquam. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Duis tempus ligula eu nulla pharetra eleifend. Pellentesque eget nisi gravida, faucibus justo ac, volutpat elit. Praesent egestas posuere elit, et imperdiet magna rhoncus eget. Donec porttitor enim lectus, quis egestas quam dignissim in. Donec dignissim sapien odio, nec molestie enim imperdiet ac. Praesent venenatis quis mi nec pretium. \section*{Displayed Text} \end{document}""" )
def create_snippets(indir, outdir, logger): files = get_filenames(indir) for filename in files: logger.info("Starting to process %s", filename) try: _, name = os.path.split(filename) name, _ = os.path.splitext(name) name = name + '.xml' outname = os.path.join(outdir, name) latex = LatexParser(filename) if latex.is_valid(): latex.clean() latex.compile_snippets(snipfile=outname, preamblefile=TEMPLATE, texdir=COMPILE_DIR) except Exception: # skip any files that cause exceptions logger.error("Could not process %s", filename) finally: if ERASE_WHEN_FINISHED: os.remove(filename)
help="set the config file") parser.add_argument("-d", "--debug", action="store_true", help="enable debug mode") parser.add_argument("-b", "--beautify", action="store_true", help="beautify code after refactoring") # refactoring tasks parser.add_argument("--remove-comments", "--remove-comments", action="store_true") parser.add_argument("--refactor-title", "--refactor-title", action="store") parser.add_argument("--refactor-section2subsection", "--refactor-section2subsection", action="store") parser.add_argument("--refactor-subsection2section", "--refactor-subsection2section", action="store") args = parser.parse_args() if args.beautify: lp = LatexParser(open(args.input, "r").read(), LatexRefactor(args.config)) else: lp = LatexParser(open(args.input, "r").read(), LatexRefactor(args.config), keep_empty_lines=True, do_not_concat_text=True) ld = lp.getResult() # execute refactoring tasks if args.remove_comments: ld.removeComments() if args.refactor_title: ld.refactorTitle(args.refactor_title) if args.refactor_section2subsection: ld.refactorSection2Subsection(args.refactor_section2subsection) if args.refactor_subsection2section: ld.refactorSubsection2Section(args.refactor_subsection2section)
def test_parser_do_not_beautify(self): self.parser = LatexParser(self.document, keep_empty_lines=True, do_not_concat_text=True) assert self.parser.getResult().getDocument(no_prefix=False) == self.document