More advance autofill.
This commit is contained in:
parent
330532fd82
commit
2a2eb5ed96
@ -7,8 +7,6 @@ def get_autofill_pattern(field):
|
||||
|
||||
def autofill(text, 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,
|
||||
get_autofill_pattern(field),
|
||||
info)
|
||||
@ -28,22 +26,41 @@ def get_autofill_info(paper):
|
||||
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):
|
||||
return pattern.replace('INFO', info)
|
||||
|
||||
|
||||
def find_pattern(text, pattern):
|
||||
pattern = pattern.replace('INFO}', '')
|
||||
start = text.find(pattern)
|
||||
after = start + len(pattern)
|
||||
info_length = text[after:].find('}')
|
||||
end = start + len(pattern) + info_length + 1
|
||||
return text[start:end]
|
||||
look_at = pattern.replace('INFO}', '')
|
||||
found = []
|
||||
start = -1
|
||||
while True:
|
||||
start = text.find(look_at, start + 1)
|
||||
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):
|
||||
return text.replace(find_pattern(text, pattern),
|
||||
fill_pattern(pattern, info))
|
||||
repl = fill_pattern(pattern, info)
|
||||
for found in find_pattern(text, pattern):
|
||||
print found
|
||||
text = text.replace(found, repl)
|
||||
return text
|
||||
|
||||
|
||||
##### ugly replace by proper #####
|
||||
|
@ -1,32 +1,40 @@
|
||||
%DO_NOT_MODIFY{
|
||||
%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}
|
||||
%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
|
||||
\usepackage{INFO} %The style location is automatically filled
|
||||
\begin{document}
|
||||
%You can edit the template of this file using: papers texnote edit_template -B
|
||||
%}
|
||||
|
||||
\begin{center}
|
||||
\Large{\textbf{\autofill{TITLE}{The title}}} \\ [0.2cm]
|
||||
\small{\textsc{\autofill{AUTHOR}{The authors}}} \\ [0.2cm]
|
||||
\normalsize{\textsc{\autofill{YEAR}{The year}}} \\ [1cm]
|
||||
\end{center}
|
||||
|
||||
%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}
|
||||
\Large{\textbf{\autofill{TITLE}{Title not found}}} \\ [0.2cm]
|
||||
\small{\textsc{\autofill{AUTHOR}{Author(s) not found}}} \\ [0.2cm]
|
||||
\normalsize{\textsc{\autofill{YEAR}{Year not found}}} \\ [1cm]
|
||||
\end{center}
|
||||
\begin{abstract}
|
||||
\autofill{ABSTRACT}{The abstract}
|
||||
\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_MODIFY{
|
||||
%You can only cite papers added in you repo.
|
||||
%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
|
||||
%[texnote]
|
||||
%bib_style = plain
|
||||
\bibliography{INFO}
|
||||
\bibliography{INFO} %The bibliography location is automatically filled
|
||||
\end{document}
|
||||
%}
|
||||
|
Loading…
x
Reference in New Issue
Block a user