Extract note feature. Ready to compile several note together.
This commit is contained in:
parent
e76dfbca8f
commit
9f1b5e9813
papers/plugs/texnote
@ -7,8 +7,6 @@
|
|||||||
\usepackage{INFO} %The style location is automatically filled
|
\usepackage{INFO} %The style location is automatically filled
|
||||||
\begin{document}
|
\begin{document}
|
||||||
%}
|
%}
|
||||||
|
|
||||||
|
|
||||||
%HEADER{
|
%HEADER{
|
||||||
%This part is the header, you can modify it as you wish. It will be removed when compiling higher level notes
|
%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 automatyically replaced with respect to the associated bibfile thanks to the \autofill{*FIELD*}{} marker.
|
||||||
|
@ -1,6 +1,27 @@
|
|||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
|
from .autofill_tools import replace_pattern
|
||||||
|
|
||||||
|
DO_NOT_MODIFY_PATTERN = '%DO_NOT_MODIFY{INFO}'
|
||||||
|
HEADER_PATTERN = '%HEADER{INFO}'
|
||||||
|
|
||||||
|
|
||||||
|
def extract_note(text):
|
||||||
|
text = replace_pattern(text, DO_NOT_MODIFY_PATTERN, 'INFO')
|
||||||
|
text = text.replace(DO_NOT_MODIFY_PATTERN, '')
|
||||||
|
text = replace_pattern(text, HEADER_PATTERN, 'INFO')
|
||||||
|
text = text.replace(HEADER_PATTERN, '')
|
||||||
|
return remove_empty_lines(text)
|
||||||
|
|
||||||
|
|
||||||
|
def remove_empty_lines(text):
|
||||||
|
cleaned_text = ''
|
||||||
|
for line in text.split('\n'):
|
||||||
|
if line.strip():
|
||||||
|
cleaned_text += line + '\n'
|
||||||
|
return cleaned_text[:-1]
|
||||||
|
|
||||||
|
|
||||||
def full_compile(full_path_to_file, verbose=False):
|
def full_compile(full_path_to_file, verbose=False):
|
||||||
FNULL = None
|
FNULL = None
|
||||||
@ -22,10 +43,10 @@ def run_command(command, full_path_to_file, stdout=None, nb_time=1):
|
|||||||
subprocess.call(cmd, stdout=stdout)
|
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):
|
def run_pdflatex(full_path_to_file, stdout=None, nb_time=1):
|
||||||
run_command('pdflatex', full_path_to_file, stdout, nb_time)
|
run_command('pdflatex', full_path_to_file, stdout, nb_time)
|
||||||
|
|
||||||
|
|
||||||
def run_bibtex(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)
|
run_command('bibtex', full_path_to_file, stdout, nb_time)
|
||||||
|
|
||||||
|
|
||||||
|
@ -13,8 +13,8 @@ from ...plugins import PapersPlugin
|
|||||||
from ...events import RemoveEvent, RenameEvent, AddEvent
|
from ...events import RemoveEvent, RenameEvent, AddEvent
|
||||||
from ...commands.helpers import add_references_argument, parse_reference
|
from ...commands.helpers import add_references_argument, parse_reference
|
||||||
|
|
||||||
|
from . import latex_tools
|
||||||
from .autofill_tools import autofill, replace_pattern
|
from .autofill_tools import autofill, replace_pattern
|
||||||
from .latex_tools import full_compile
|
|
||||||
|
|
||||||
|
|
||||||
SECTION = 'texnote'
|
SECTION = 'texnote'
|
||||||
@ -46,6 +46,7 @@ class TexnotePlugin(PapersPlugin):
|
|||||||
('generate_bib', self.generate_bib),
|
('generate_bib', self.generate_bib),
|
||||||
('clean', self.clean),
|
('clean', self.clean),
|
||||||
('generate_pdf', self.generate_pdf),
|
('generate_pdf', self.generate_pdf),
|
||||||
|
('extract_note', self.extract_note),
|
||||||
])
|
])
|
||||||
|
|
||||||
def _ensure_init(self):
|
def _ensure_init(self):
|
||||||
@ -108,6 +109,10 @@ class TexnotePlugin(PapersPlugin):
|
|||||||
default=True, help="don't clean document afterwards")
|
default=True, help="don't clean document afterwards")
|
||||||
p.add_argument('-v', '--verbose', action='store_true', dest='verbose',
|
p.add_argument('-v', '--verbose', action='store_true', dest='verbose',
|
||||||
default=False, help="display stdout")
|
default=False, help="display stdout")
|
||||||
|
# extract_note
|
||||||
|
p = sub.add_parser('extract_note',
|
||||||
|
help='extract core note from its reference')
|
||||||
|
add_references_argument(p, single=True)
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
def command(self, args):
|
def command(self, args):
|
||||||
@ -221,7 +226,7 @@ class TexnotePlugin(PapersPlugin):
|
|||||||
rp = repo.Repository(config())
|
rp = repo.Repository(config())
|
||||||
citekey = parse_reference(rp, reference)
|
citekey = parse_reference(rp, reference)
|
||||||
path = self.get_texfile(citekey, autofill=True)
|
path = self.get_texfile(citekey, autofill=True)
|
||||||
full_compile(path, verbose)
|
latex_tools.full_compile(path, verbose)
|
||||||
if clean:
|
if clean:
|
||||||
self.clean(force=True)
|
self.clean(force=True)
|
||||||
if open_pdf:
|
if open_pdf:
|
||||||
@ -231,6 +236,14 @@ class TexnotePlugin(PapersPlugin):
|
|||||||
cmd.append(os.path.splitext(path)[0] + '.pdf')
|
cmd.append(os.path.splitext(path)[0] + '.pdf')
|
||||||
subprocess.Popen(cmd)
|
subprocess.Popen(cmd)
|
||||||
|
|
||||||
|
def extract_note(self, reference):
|
||||||
|
rp = repo.Repository(config())
|
||||||
|
citekey = parse_reference(rp, reference)
|
||||||
|
path = self.get_texfile(citekey, autofill=True)
|
||||||
|
with open(path) as f:
|
||||||
|
text = f.read()
|
||||||
|
print latex_tools.extract_note(text)
|
||||||
|
|
||||||
|
|
||||||
@AddEvent.listen()
|
@AddEvent.listen()
|
||||||
def create(addevent):
|
def create(addevent):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user