More advance autofill.

main
Jonathan Grizou 12 years ago
parent 330532fd82
commit 2a2eb5ed96

@ -7,8 +7,6 @@ def get_autofill_pattern(field):
def autofill(text, paper): def autofill(text, paper):
for field, info in get_autofill_info(paper): for field, info in get_autofill_info(paper):
print find_pattern(text, get_autofill_pattern(field))
print fill_pattern(get_autofill_pattern(field), info)
text = replace_pattern(text, text = replace_pattern(text,
get_autofill_pattern(field), get_autofill_pattern(field),
info) info)
@ -28,22 +26,41 @@ def get_autofill_info(paper):
return info return info
def find_first_level_delimiter(text, opening='{', closing='}'):
if opening in text:
match = text.split(opening,1)[1]
cnt = 1
for index in xrange(len(match)):
if match[index] in (opening + closing):
cnt = (cnt + 1) if match[index] == opening else (cnt - 1)
if not cnt:
return match[:index]
def fill_pattern(pattern, info): def fill_pattern(pattern, info):
return pattern.replace('INFO', info) return pattern.replace('INFO', info)
def find_pattern(text, pattern): def find_pattern(text, pattern):
pattern = pattern.replace('INFO}', '') look_at = pattern.replace('INFO}', '')
start = text.find(pattern) found = []
after = start + len(pattern) start = -1
info_length = text[after:].find('}') while True:
end = start + len(pattern) + info_length + 1 start = text.find(look_at, start + 1)
return text[start:end] if start < 0:
break
delim_start = start + len(look_at) - 1
repl = find_first_level_delimiter(text[delim_start:])
found.append(pattern.replace('INFO', repl))
return found
def replace_pattern(text, pattern, info): def replace_pattern(text, pattern, info):
return text.replace(find_pattern(text, pattern), repl = fill_pattern(pattern, info)
fill_pattern(pattern, info)) for found in find_pattern(text, pattern):
print found
text = text.replace(found, repl)
return text
##### ugly replace by proper ##### ##### ugly replace by proper #####

@ -1,32 +1,40 @@
%DO_NOT_MODIFY{ %DO_NOT_MODIFY{
%This file is the starting point for all notes %This file is the starting point for all notes
%TITLE, AUTHOR, YEAR, ABSTRACT will be automatyically replaced with respect to the associated bibfile thanks to the \autofill{*FIELD*}{} marker. %You can edit the template of this file using: papers texnote edit_template -B
\documentclass{article} \documentclass{article}
%All texnote much share the same style so that we can compile them all together without problem %All texnote much share the same style so that we can compile them all together without problem
\usepackage{INFO}
%You are free to edit the style file using: papers texnote edit_template -S %You are free to edit the style file using: papers texnote edit_template -S
\usepackage{INFO} %The style location is automatically filled
\begin{document} \begin{document}
%You can edit the template of this file using: papers texnote edit_template -B
%} %}
%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.
\begin{center} \begin{center}
\Large{\textbf{\autofill{TITLE}{The title}}} \\ [0.2cm] \Large{\textbf{\autofill{TITLE}{Title not found}}} \\ [0.2cm]
\small{\textsc{\autofill{AUTHOR}{The authors}}} \\ [0.2cm] \small{\textsc{\autofill{AUTHOR}{Author(s) not found}}} \\ [0.2cm]
\normalsize{\textsc{\autofill{YEAR}{The year}}} \\ [1cm] \normalsize{\textsc{\autofill{YEAR}{Year not found}}} \\ [1cm]
\end{center} \end{center}
\begin{abstract} \begin{abstract}
\autofill{ABSTRACT}{The abstract} \autofill{ABSTRACT}{Abstract not found}
\end{abstract} \end{abstract}
%Write your notes below
%Do not use \section{} or \subsection{} as they may be source of problems when concatenating notes.
%}
%DO_NOT_MODIFY{ %DO_NOT_MODIFY{
%You can only cite papers added in you repo. %You can only cite papers added in you repo.
%To update the bib file with latest papers info: papers texnote generate_bib %To update the bib file with latest papers info: papers texnote generate_bib
\bibliographystyle{INFO} %default is ieeetr \bibliographystyle{INFO} %The bibstyle is automatically filled (default is ieeetr)
%You can change the bibliography style in the config file : .papersrc %You can change the bibliography style in the config file : .papersrc
%[texnote] %[texnote]
%bib_style = plain %bib_style = plain
\bibliography{INFO} \bibliography{INFO} %The bibliography location is automatically filled
\end{document} \end{document}
%} %}

Loading…
Cancel
Save