def inline_prev(commit_ref, root_tex_path): """Inline the previous manuscript in the git tree. Parameters ---------- commif_ref : str Commit reference string. root_tex_path : str Path to the root tex document in the filesystem. Returns ------- output_path : str Path to the inlined latex document for latexdiff processing. """ log = logging.getLogger(__name__) log.debug("inline_prev root_tex") log.debug(root_tex_path) git_root = absolute_git_root_dir(root_tex_path) rel_root_tex_path = os.path.relpath(os.path.abspath(root_tex_path), git_root) root_text = read_git_blob(commit_ref, rel_root_tex_path, repo_dir=git_root) log.debug("prev root_text") log.debug(root_text) root_text = remove_comments(root_text) root_text = inline_blob(commit_ref, root_text, base_dir=os.path.dirname(rel_root_tex_path), repo_dir=git_root) output_path = "_prev.tex" if os.path.exists(output_path): os.remove(output_path) with codecs.open(output_path, 'w', encoding='utf-8') as f: f.write(root_text) return output_path
def take_action(self, parsed_args): dirname = os.path.join("build", parsed_args.name) if not os.path.exists(dirname): os.makedirs(dirname) self._build_style = parsed_args.style self._ext_priority = parsed_args.exts self._max_size = parsed_args.maxsize bbl_path = ".".join((os.path.splitext(self.app.options.master)[0], 'bbl')) with codecs.open(self.app.options.master, 'r', encoding='utf-8') as f: root_text = f.read() tex = inline(root_text) tex = remove_comments(tex) tex = self._process_figures(tex, dirname) if os.path.exists(bbl_path): with codecs.open(bbl_path, 'r', encoding='utf-8') as f: bbl_text = f.read() tex = inline_bbl(tex, bbl_text) else: self.log.debug("Skipping .bbl installation") if self._build_style == "aastex": output_tex_path = os.path.join(dirname, "ms.tex") else: output_tex_path = os.path.join( dirname, os.path.basename(self.app.options.master)) self._write_tex(tex, output_tex_path)
def inline_current(root_tex_path): """Inline the current manuscript.""" base_dir = os.path.dirname(root_tex_path) with codecs.open(root_tex_path, 'r', encoding='utf-8') as f: root_text = f.read() root_text = remove_comments(root_text) root_text = inline(root_text, base_dir=base_dir) output_path = "_current.tex" if os.path.exists(output_path): os.remove(output_path) with codecs.open(output_path, 'w', encoding='utf-8') as f: f.write(root_text) return output_path