Extract note feature. Ready to compile several note together.
This commit is contained in:
parent
e76dfbca8f
commit
9f1b5e9813
@ -7,8 +7,6 @@
|
||||
\usepackage{INFO} %The style location is automatically filled
|
||||
\begin{document}
|
||||
%}
|
||||
|
||||
|
||||
%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.
|
||||
|
@ -1,6 +1,27 @@
|
||||
import os
|
||||
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):
|
||||
FNULL = None
|
||||
@ -22,10 +43,10 @@ def run_command(command, full_path_to_file, stdout=None, nb_time=1):
|
||||
subprocess.call(cmd, stdout=stdout)
|
||||
os.chdir(origWD) # get back to our original working directory
|
||||
|
||||
|
||||
def run_pdflatex(full_path_to_file, stdout=None, nb_time=1):
|
||||
run_command('pdflatex', full_path_to_file, stdout, nb_time)
|
||||
|
||||
|
||||
def run_bibtex(full_path_to_file, stdout=None, nb_time=1):
|
||||
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 ...commands.helpers import add_references_argument, parse_reference
|
||||
|
||||
from . import latex_tools
|
||||
from .autofill_tools import autofill, replace_pattern
|
||||
from .latex_tools import full_compile
|
||||
|
||||
|
||||
SECTION = 'texnote'
|
||||
@ -46,6 +46,7 @@ class TexnotePlugin(PapersPlugin):
|
||||
('generate_bib', self.generate_bib),
|
||||
('clean', self.clean),
|
||||
('generate_pdf', self.generate_pdf),
|
||||
('extract_note', self.extract_note),
|
||||
])
|
||||
|
||||
def _ensure_init(self):
|
||||
@ -108,6 +109,10 @@ class TexnotePlugin(PapersPlugin):
|
||||
default=True, help="don't clean document afterwards")
|
||||
p.add_argument('-v', '--verbose', action='store_true', dest='verbose',
|
||||
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
|
||||
|
||||
def command(self, args):
|
||||
@ -221,7 +226,7 @@ class TexnotePlugin(PapersPlugin):
|
||||
rp = repo.Repository(config())
|
||||
citekey = parse_reference(rp, reference)
|
||||
path = self.get_texfile(citekey, autofill=True)
|
||||
full_compile(path, verbose)
|
||||
latex_tools.full_compile(path, verbose)
|
||||
if clean:
|
||||
self.clean(force=True)
|
||||
if open_pdf:
|
||||
@ -231,6 +236,14 @@ class TexnotePlugin(PapersPlugin):
|
||||
cmd.append(os.path.splitext(path)[0] + '.pdf')
|
||||
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()
|
||||
def create(addevent):
|
||||
|
Loading…
x
Reference in New Issue
Block a user