From 8524b9d5b887797bce92e0630ff4a1964be8e69b Mon Sep 17 00:00:00 2001 From: Jonathan Grizou Date: Tue, 9 Jul 2013 19:56:04 +0200 Subject: [PATCH] Allow for glossary in texnote. Implies ruuning makeglosaries in latex_tools and changes in template files. --- papers/plugs/texnote/default_body.tex | 7 +++++-- papers/plugs/texnote/default_style.sty | 7 +++++++ papers/plugs/texnote/latex_tools.py | 4 ++++ papers/plugs/texnote/texnote.py | 13 +++++++++++-- 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/papers/plugs/texnote/default_body.tex b/papers/plugs/texnote/default_body.tex index a0f2da9..0edfb26 100644 --- a/papers/plugs/texnote/default_body.tex +++ b/papers/plugs/texnote/default_body.tex @@ -9,7 +9,7 @@ %} %HEADER{ %This part is the header, you can modify it as you wish. It will be removed when compiling higher level notes -%TITLE, AUTHOR, YEAR, ABSTRACT will be automatyically replaced with respect to the associated bibfile thanks to the \autofill{*FIELD*}{} marker. +%TITLE, AUTHOR, YEAR, ABSTRACT will be automatically replaced with respect to the associated bibfile thanks to the \autofill{*FIELD*}{} marker. \begin{center} \Large{\textbf{\autofill{TITLE}{Title not found}}} \\ [0.2cm] \small{\textsc{\autofill{AUTHOR}{Author(s) not found}}} \\ [0.2cm] @@ -19,7 +19,7 @@ \autofill{ABSTRACT}{Abstract not found} \end{abstract} %Write your notes below -%Do not use \section{} or \subsection{} as they may be source of problems when concatenating notes. +%Do not use \section{} or \subsection{} as they may be source of problems when concatenating notes. Use \paragraph{} instead. %} @@ -34,5 +34,8 @@ %[texnote] %bib_style = plain \bibliography{INFO} %The bibliography location is automatically filled +%The glossary style is default +\printglossary +%You can add a new glossary entry using \dictentry{'name'}{'description'} (see style file). This will automatically add a new reference and display it in the glossary even if never referenced (using \gls{'name'}). \end{document} %} diff --git a/papers/plugs/texnote/default_style.sty b/papers/plugs/texnote/default_style.sty index 0a0ee2e..d08a003 100644 --- a/papers/plugs/texnote/default_style.sty +++ b/papers/plugs/texnote/default_style.sty @@ -1,4 +1,11 @@ %DO_NOT_MODIFY{ %Dummy command used as marker for the autofill \newcommand{\autofill}[2]{#2} +%command for easy glossary, requires to run: 'makeglossaries filename' +\usepackage[nonumberlist]{glossaries} +\newcommand{\dictentry}[2]{% + \newglossaryentry{#1}{name=#1,description={#2}}% + \glslink{#1}{}% +} +\makeglossaries %} diff --git a/papers/plugs/texnote/latex_tools.py b/papers/plugs/texnote/latex_tools.py index 042eb28..e148807 100644 --- a/papers/plugs/texnote/latex_tools.py +++ b/papers/plugs/texnote/latex_tools.py @@ -30,6 +30,7 @@ def full_compile(full_path_to_file, verbose=False): filename, extension = os.path.splitext(full_path_to_file) run_pdflatex(filename, stdout=FNULL) run_bibtex(filename, stdout=FNULL) + run_makeglossaries(filename, stdout=FNULL) run_pdflatex(filename, stdout=FNULL, nb_time=3) @@ -50,3 +51,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) diff --git a/papers/plugs/texnote/texnote.py b/papers/plugs/texnote/texnote.py index 2a9ff05..a99fd48 100644 --- a/papers/plugs/texnote/texnote.py +++ b/papers/plugs/texnote/texnote.py @@ -125,8 +125,11 @@ class TexnotePlugin(PapersPlugin): def _texfile(self, citekey): return os.path.join(DIR, citekey + '.tex') + def _exist_texfile(self, citekey): + return files.check_file(self._texfile(citekey)) + def _ensure_texfile(self, citekey): - if not files.check_file(self._texfile(citekey)): + if not self._exist_texfile(citekey): shutil.copy(TPL_BODY, self._texfile(citekey)) def get_bib_style(self): @@ -189,7 +192,13 @@ class TexnotePlugin(PapersPlugin): os.remove(self.get_texfile(citekey)) def rename(self, old_citekey, new_citekey, overwrite=False): - shutil.move(self.get_texfile(old_citekey), self.get_texfile(new_citekey)) + if self._exist_texfile(old_citekey): + if not overwrite and self._exist_texfile(new_citekey): + ui = get_ui() + are_you_sure = 'Are you sure you want to delete [{}]'.format(citekey) + sure = ui.input_yn(question=are_you_sure, default='n') + if overwrite or sure: + shutil.move(self.get_texfile(old_citekey), self.get_texfile(new_citekey)) def generate_bib(self): if files.check_file(TPL_BIB):