From 6b738a3f6c1be565a937837ea627063d604a4075 Mon Sep 17 00:00:00 2001 From: jgrizou Date: Fri, 12 Jul 2013 11:17:05 +0200 Subject: [PATCH] Add autofill keyword in texnote --- papers/plugs/texnote/autofill_tools.py | 10 +++++++--- papers/plugs/texnote/default_body.tex | 1 + papers/plugs/texnote/latex_tools.py | 13 ++++++++++--- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/papers/plugs/texnote/autofill_tools.py b/papers/plugs/texnote/autofill_tools.py index 784e5cb..0f60a24 100644 --- a/papers/plugs/texnote/autofill_tools.py +++ b/papers/plugs/texnote/autofill_tools.py @@ -1,3 +1,5 @@ +from .latex_tools import format_for_latex + AUTOFILL_TPL = '\\autofill{FIELD}{INFO}' @@ -9,12 +11,13 @@ def autofill(text, paper): for field, info in get_autofill_info(paper): text = replace_pattern(text, get_autofill_pattern(field), - info) + format_for_latex(info)) return text + def get_autofill_info(paper): fields = paper.bibentry.fields - + tags = paper.tags info = [] if 'year' in fields: info.append(('YEAR', fields['year'])) @@ -23,12 +26,13 @@ def get_autofill_info(paper): if 'abstract' in fields: info.append(('ABSTRACT', fields['abstract'])) info.append(('AUTHOR', get_author_as_str(paper))) + info.append(('TAG', ', '.join(tags))) return info def find_first_level_delimiter(text, opening='{', closing='}'): if opening in text: - match = text.split(opening,1)[1] + match = text.split(opening, 1)[1] cnt = 1 for index in xrange(len(match)): if match[index] in (opening + closing): diff --git a/papers/plugs/texnote/default_body.tex b/papers/plugs/texnote/default_body.tex index 0edfb26..88d5d5e 100644 --- a/papers/plugs/texnote/default_body.tex +++ b/papers/plugs/texnote/default_body.tex @@ -15,6 +15,7 @@ \small{\textsc{\autofill{AUTHOR}{Author(s) not found}}} \\ [0.2cm] \normalsize{\textsc{\autofill{YEAR}{Year not found}}} \\ [1cm] \end{center} +\textbf{Keywords:} \autofill{TAG}{Tags not found} \begin{abstract} \autofill{ABSTRACT}{Abstract not found} \end{abstract} diff --git a/papers/plugs/texnote/latex_tools.py b/papers/plugs/texnote/latex_tools.py index e148807..0ef16bc 100644 --- a/papers/plugs/texnote/latex_tools.py +++ b/papers/plugs/texnote/latex_tools.py @@ -1,12 +1,18 @@ import os import subprocess -from .autofill_tools import replace_pattern DO_NOT_MODIFY_PATTERN = '%DO_NOT_MODIFY{INFO}' HEADER_PATTERN = '%HEADER{INFO}' +def format_for_latex(text): + text = text.replace('_', '\_') + return text + +from .autofill_tools import replace_pattern + + def extract_note(text): text = replace_pattern(text, DO_NOT_MODIFY_PATTERN, 'INFO') text = text.replace(DO_NOT_MODIFY_PATTERN, '') @@ -35,14 +41,14 @@ def full_compile(full_path_to_file, verbose=False): def run_command(command, full_path_to_file, stdout=None, nb_time=1): - origWD = os.getcwd() # remember our original working directory + origWD = os.getcwd() # remember our original working directory folder, filename = os.path.split(full_path_to_file) os.chdir(folder) for _ in xrange(nb_time): cmd = command.split() cmd.append(filename) subprocess.call(cmd, stdout=stdout) - os.chdir(origWD) # get back to our original working directory + os.chdir(origWD) # get back to our original working directory def run_pdflatex(full_path_to_file, stdout=None, nb_time=1): @@ -52,5 +58,6 @@ def run_pdflatex(full_path_to_file, stdout=None, nb_time=1): def run_bibtex(full_path_to_file, stdout=None, nb_time=1): run_command('bibtex', full_path_to_file, stdout, nb_time) + def run_makeglossaries(full_path_to_file, stdout=None, nb_time=1): run_command('makeglossaries', full_path_to_file, stdout, nb_time)