pyeasyphd 0.0.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of pyeasyphd might be problematic. Click here for more details.
- pyeasyphd/.python-version +1 -0
- pyeasyphd/Main.sublime-menu +43 -0
- pyeasyphd/__init__.py +0 -0
- pyeasyphd/bib/__init__.py +1 -0
- pyeasyphd/bib/bibtexbase/__init__.py +7 -0
- pyeasyphd/bib/bibtexbase/standardize/_base.py +36 -0
- pyeasyphd/bib/bibtexbase/standardize/default_data.py +97 -0
- pyeasyphd/bib/bibtexbase/standardize/do_on_bib.py +54 -0
- pyeasyphd/bib/bibtexbase/standardize/do_on_comment_block.py +38 -0
- pyeasyphd/bib/bibtexbase/standardize/do_on_entry_block.py +310 -0
- pyeasyphd/bib/bibtexbase/standardize/do_on_preamble_block.py +35 -0
- pyeasyphd/bib/bibtexbase/standardize/do_on_string_block.py +34 -0
- pyeasyphd/bib/bibtexbase/standardize_bib.py +75 -0
- pyeasyphd/bib/bibtexparser/__init__.py +47 -0
- pyeasyphd/bib/bibtexparser/bibtex_format.py +87 -0
- pyeasyphd/bib/bibtexparser/exceptions.py +64 -0
- pyeasyphd/bib/bibtexparser/library.py +207 -0
- pyeasyphd/bib/bibtexparser/middlewares/block/add.py +94 -0
- pyeasyphd/bib/bibtexparser/middlewares/block/authors.py +22 -0
- pyeasyphd/bib/bibtexparser/middlewares/block/doi_url.py +62 -0
- pyeasyphd/bib/bibtexparser/middlewares/block/entry_field_keys_normalize.py +47 -0
- pyeasyphd/bib/bibtexparser/middlewares/block/entry_field_keys_replace.py +31 -0
- pyeasyphd/bib/bibtexparser/middlewares/block/entry_field_values_normalize.py +222 -0
- pyeasyphd/bib/bibtexparser/middlewares/block/entry_fields_delete.py +34 -0
- pyeasyphd/bib/bibtexparser/middlewares/block/entry_fields_keep.py +33 -0
- pyeasyphd/bib/bibtexparser/middlewares/block/entry_fields_sort.py +70 -0
- pyeasyphd/bib/bibtexparser/middlewares/block/entry_types.py +15 -0
- pyeasyphd/bib/bibtexparser/middlewares/block/journal_booktitle.py +113 -0
- pyeasyphd/bib/bibtexparser/middlewares/block/month_year.py +34 -0
- pyeasyphd/bib/bibtexparser/middlewares/block/number_volume.py +21 -0
- pyeasyphd/bib/bibtexparser/middlewares/block/pages.py +28 -0
- pyeasyphd/bib/bibtexparser/middlewares/block/title.py +20 -0
- pyeasyphd/bib/bibtexparser/middlewares/library/generating_entrykeys.py +98 -0
- pyeasyphd/bib/bibtexparser/middlewares/library/keeping_blocks.py +29 -0
- pyeasyphd/bib/bibtexparser/middlewares/library/sorting_blocks.py +124 -0
- pyeasyphd/bib/bibtexparser/middlewares/middleware.py +222 -0
- pyeasyphd/bib/bibtexparser/middlewares/parsestack.py +13 -0
- pyeasyphd/bib/bibtexparser/middlewares/utils.py +226 -0
- pyeasyphd/bib/bibtexparser/middlewares_library_to_library.py +414 -0
- pyeasyphd/bib/bibtexparser/middlewares_library_to_str.py +42 -0
- pyeasyphd/bib/bibtexparser/middlewares_str_to_library.py +35 -0
- pyeasyphd/bib/bibtexparser/middlewares_str_to_str.py +29 -0
- pyeasyphd/bib/bibtexparser/model.py +481 -0
- pyeasyphd/bib/bibtexparser/splitter.py +151 -0
- pyeasyphd/bib/core/__init__.py +18 -0
- pyeasyphd/bib/core/convert_library_to_library.py +31 -0
- pyeasyphd/bib/core/convert_library_to_str.py +199 -0
- pyeasyphd/bib/core/convert_str_to_library.py +34 -0
- pyeasyphd/bib/core/convert_str_to_str.py +27 -0
- pyeasyphd/main/__init__.py +17 -0
- pyeasyphd/main/basic_input.py +149 -0
- pyeasyphd/main/pandoc_md_to.py +361 -0
- pyeasyphd/main/python_run_bib.py +73 -0
- pyeasyphd/main/python_run_md.py +235 -0
- pyeasyphd/main/python_run_tex.py +149 -0
- pyeasyphd/main/python_writers.py +212 -0
- pyeasyphd/pyeasyphd.py +72 -0
- pyeasyphd/pyeasyphd.sublime-settings +235 -0
- pyeasyphd/pyeasyphd.sublime-syntax +5 -0
- pyeasyphd/tools/__init__.py +30 -0
- pyeasyphd/tools/compare/compare_bibs.py +234 -0
- pyeasyphd/tools/experiments_base.py +203 -0
- pyeasyphd/tools/format_save_bibs.py +178 -0
- pyeasyphd/tools/generate/generate_from_bibs.py +447 -0
- pyeasyphd/tools/generate/generate_links.py +356 -0
- pyeasyphd/tools/py_run_bib_md_tex.py +378 -0
- pyeasyphd/tools/replace/replace.py +81 -0
- pyeasyphd/tools/search/data.py +318 -0
- pyeasyphd/tools/search/search_base.py +118 -0
- pyeasyphd/tools/search/search_core.py +326 -0
- pyeasyphd/tools/search/search_keywords.py +227 -0
- pyeasyphd/tools/search/search_writers.py +288 -0
- pyeasyphd/tools/search/utils.py +152 -0
- pyeasyphd/tools/spider/process_spider_bib.py +247 -0
- pyeasyphd/tools/spider/process_spider_url.py +74 -0
- pyeasyphd/tools/spider/process_spider_url_bib.py +62 -0
- pyeasyphd/utils/utils.py +62 -0
- pyeasyphd-0.0.2.dist-info/METADATA +27 -0
- pyeasyphd-0.0.2.dist-info/RECORD +80 -0
- pyeasyphd-0.0.2.dist-info/WHEEL +4 -0
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import re
|
|
3
|
+
from typing import Any, Dict, List, Optional
|
|
4
|
+
|
|
5
|
+
from pyadvtools import (
|
|
6
|
+
delete_files,
|
|
7
|
+
insert_list_in_list,
|
|
8
|
+
read_list,
|
|
9
|
+
write_list,
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
from .basic_input import BasicInput
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class PythonRunTex(BasicInput):
|
|
16
|
+
"""Python tex.
|
|
17
|
+
|
|
18
|
+
Args:
|
|
19
|
+
options (Dict[str, Any]): Options.
|
|
20
|
+
|
|
21
|
+
Attributes:
|
|
22
|
+
run_latex (bool = False): Whether to run latex.
|
|
23
|
+
pdflatex_xelatex (str = "pdflatex"): pdflatex or xelatex.
|
|
24
|
+
delete_run_latex_cache (bool = True): Whether to delete run latex cache.
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
def __init__(self, options: Dict[str, Any]) -> None:
|
|
28
|
+
super().__init__(options)
|
|
29
|
+
|
|
30
|
+
# for tex
|
|
31
|
+
self.final_output_main_tex_name: str = options.get("final_output_main_tex_name", "")
|
|
32
|
+
self.run_latex: bool = options.get("run_latex", False)
|
|
33
|
+
self.pdflatex_xelatex: str = options.get("pdflatex_xelatex", "pdflatex") # pdflatex, xelatex
|
|
34
|
+
self.delete_run_latex_cache: bool = options.get("delete_run_latex_cache", True)
|
|
35
|
+
self.latex_clean_file_types: Optional[List[str]] = options.get("latex_clean_file_types", None)
|
|
36
|
+
|
|
37
|
+
def generate_standard_tex_data_list(
|
|
38
|
+
self,
|
|
39
|
+
data_list_body: List[str],
|
|
40
|
+
output_tex_name: str,
|
|
41
|
+
path_output: str,
|
|
42
|
+
figure_folder_name: str = "figs",
|
|
43
|
+
tex_folder_name: str = "tex",
|
|
44
|
+
bib_folder_name: str = "bib",
|
|
45
|
+
bib_name: str = "abbr.bib",
|
|
46
|
+
template_name: str = "article",
|
|
47
|
+
) -> List[str]:
|
|
48
|
+
# for figures
|
|
49
|
+
for i in range(len(data_list_body)):
|
|
50
|
+
if re.search(r"\\includegraphics", data_list_body[i]):
|
|
51
|
+
data_list_body[i] = data_list_body[i].replace("./Figures/", f"./{figure_folder_name}/")
|
|
52
|
+
data_list_body[i] = data_list_body[i].replace("Figures/", f"{figure_folder_name}/")
|
|
53
|
+
write_list(data_list_body, output_tex_name, "w", os.path.join(path_output, tex_folder_name), False)
|
|
54
|
+
|
|
55
|
+
self._special_operate_tex(
|
|
56
|
+
data_list_body, template_name, output_tex_name, path_output, tex_folder_name, bib_folder_name, bib_name
|
|
57
|
+
)
|
|
58
|
+
return data_list_body
|
|
59
|
+
|
|
60
|
+
# for tex files
|
|
61
|
+
def _special_operate_tex(
|
|
62
|
+
self,
|
|
63
|
+
data_list_body: List[str],
|
|
64
|
+
template_name: str,
|
|
65
|
+
output_tex_name: str,
|
|
66
|
+
path_output: str,
|
|
67
|
+
tex_folder_name: str,
|
|
68
|
+
bib_folder_name: str,
|
|
69
|
+
bib_name: str,
|
|
70
|
+
) -> None:
|
|
71
|
+
# read template data
|
|
72
|
+
template_h, template_t = [], []
|
|
73
|
+
if template_name.lower() == "paper":
|
|
74
|
+
template_h, template_t = self.article_template_header_tex, self.article_template_tail_tex
|
|
75
|
+
elif template_name.lower() == "beamer":
|
|
76
|
+
template_h, template_t = self.beamer_template_header_tex, self.beamer_template_tail_tex
|
|
77
|
+
|
|
78
|
+
# style
|
|
79
|
+
if usepackages := self.usepackages_tex:
|
|
80
|
+
usepackages.insert(0, "\n")
|
|
81
|
+
|
|
82
|
+
# command
|
|
83
|
+
if math_commands := self.math_commands_tex:
|
|
84
|
+
math_commands.insert(0, "\n")
|
|
85
|
+
|
|
86
|
+
# main name
|
|
87
|
+
main_name = self.final_output_main_tex_name
|
|
88
|
+
if len(main_name) == 0:
|
|
89
|
+
main_name = output_tex_name.split(".text")[0] + "_main.tex"
|
|
90
|
+
if main_name.lower() == output_tex_name.lower():
|
|
91
|
+
main_name = main_name.split(".tex")[0] + "_.tex"
|
|
92
|
+
if main_name[-4:] != ".tex":
|
|
93
|
+
main_name = main_name + ".tex"
|
|
94
|
+
|
|
95
|
+
data_list = []
|
|
96
|
+
if (len(template_h) != 0) and (len(template_t) != 0):
|
|
97
|
+
# header
|
|
98
|
+
data_list = insert_list_in_list(template_h, usepackages, r"\\documentclass", "after")
|
|
99
|
+
data_list = insert_list_in_list(data_list, math_commands, r"\\documentclass", "after")
|
|
100
|
+
|
|
101
|
+
if template_name.lower() == "beamer":
|
|
102
|
+
data_list = insert_list_in_list(data_list, ["\n\\def\\allfiles{}\n"], r"\\documentclass", "after")
|
|
103
|
+
|
|
104
|
+
if self.pdflatex_xelatex == "xelatex":
|
|
105
|
+
data_list = insert_list_in_list(data_list, ["\n\\def\\cn{}\n"], r"\\documentclass", "after")
|
|
106
|
+
|
|
107
|
+
# for bib
|
|
108
|
+
regex = re.compile(r"\\addbibresource{\./References/References\.bib}")
|
|
109
|
+
for i in range(len(data_list)):
|
|
110
|
+
mch = regex.search(data_list[i])
|
|
111
|
+
if not mch:
|
|
112
|
+
continue
|
|
113
|
+
if bib_folder_name:
|
|
114
|
+
data_list[i] = "\\addbibresource{" + f"./{bib_folder_name}/{bib_name}" + "}\n"
|
|
115
|
+
else:
|
|
116
|
+
data_list[i] = "\\addbibresource{" + f"./{bib_name}" + "}\n"
|
|
117
|
+
|
|
118
|
+
# body
|
|
119
|
+
if len(data_list_body) != 0:
|
|
120
|
+
data_list.append("\n")
|
|
121
|
+
data_list.extend(data_list_body)
|
|
122
|
+
data_list.append("\n")
|
|
123
|
+
|
|
124
|
+
# tail
|
|
125
|
+
data_list.extend(template_t)
|
|
126
|
+
|
|
127
|
+
# save file
|
|
128
|
+
write_list(data_list, main_name, "w", path_output, False)
|
|
129
|
+
else:
|
|
130
|
+
data_list = read_list(output_tex_name, "r", os.path.join(path_output, tex_folder_name))
|
|
131
|
+
write_list(data_list, main_name, "w", path_output, False)
|
|
132
|
+
|
|
133
|
+
# run latex
|
|
134
|
+
if self.run_latex:
|
|
135
|
+
os.chdir(path_output)
|
|
136
|
+
try:
|
|
137
|
+
os.system("latexmk -{} {}".format(self.pdflatex_xelatex, main_name))
|
|
138
|
+
except Exception as e:
|
|
139
|
+
print(e)
|
|
140
|
+
|
|
141
|
+
# delete cache
|
|
142
|
+
if self.delete_run_latex_cache:
|
|
143
|
+
if self.latex_clean_file_types is not None:
|
|
144
|
+
postfix = self.latex_clean_file_types
|
|
145
|
+
else:
|
|
146
|
+
postfix = ['.aux', '.bbl', '.bcf', '.blg', '.fdb_latexmk', '.fls', '.log', '.out', '.run.xml']
|
|
147
|
+
postfix.extend(['.synctex.gz', '.gz', '.nav', '.snm', '.toc', '.xdv'])
|
|
148
|
+
delete_files(path_output, postfix)
|
|
149
|
+
return None
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import re
|
|
3
|
+
from typing import Any, Dict, List, Optional, Tuple, Union
|
|
4
|
+
|
|
5
|
+
from pyadvtools import (
|
|
6
|
+
write_list,
|
|
7
|
+
)
|
|
8
|
+
|
|
9
|
+
from ..bib.bibtexparser import BibtexFormat, Block, Library
|
|
10
|
+
from ..bib.core import ConvertLibrayToStr
|
|
11
|
+
from .basic_input import BasicInput
|
|
12
|
+
from .python_run_bib import PythonRunBib
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class PythonWriters(BasicInput):
|
|
16
|
+
"""Python writers.
|
|
17
|
+
|
|
18
|
+
Args:
|
|
19
|
+
options (Dict[str, Any]): Options.
|
|
20
|
+
|
|
21
|
+
Attributes:
|
|
22
|
+
bib_for_abbr_name (str = "abbr.bib"): Bib for abbr name.
|
|
23
|
+
bib_for_zotero_name (str = "zotero.bib"): Bib for zotero name.
|
|
24
|
+
bib_for_save_name (str = "save.bib"): Bib for save name.
|
|
25
|
+
choose_abbr_zotero_save (str = "save"): Choose "abbr", "zotero", or "save".
|
|
26
|
+
display_google_connected_scite (List[str] = ["google", "connected", "scite"]): Choose multiple items.
|
|
27
|
+
"""
|
|
28
|
+
|
|
29
|
+
def __init__(self, options: Dict[str, Any]) -> None:
|
|
30
|
+
options["is_sort_entry_fields"] = options.get("is_sort_entry_fields", True)
|
|
31
|
+
options["is_sort_blocks"] = options.get("is_sort_blocks", True)
|
|
32
|
+
options["sort_entries_by_field_keys_reverse"] = options.get("sort_entries_by_field_keys_reverse", True)
|
|
33
|
+
super().__init__(options)
|
|
34
|
+
|
|
35
|
+
self.bib_for_abbr_name = options.get("bib_for_abbr_name", "abbr.bib")
|
|
36
|
+
self.bib_for_zotero_name = options.get("bib_for_zotero_name", "zotero.bib")
|
|
37
|
+
self.bib_for_save_name = options.get("bib_for_save_name", "save.bib")
|
|
38
|
+
self.choose_abbr_zotero_save = options.get("choose_abbr_zotero_save", "save")
|
|
39
|
+
|
|
40
|
+
self.display_google_connected_scite = options.get(
|
|
41
|
+
"display_google_connected_scite", ["google", "connected", "scite"]
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
self.bibtex_format_indent = options.get("bibtex_format_indent", " ")
|
|
45
|
+
self.bibtex_format_trailing_comma = options.get("bibtex_format_trailing_comma", True)
|
|
46
|
+
self.bibtex_format_block_separator = options.get("bibtex_format_block_separator", "")
|
|
47
|
+
|
|
48
|
+
bibtex_format = BibtexFormat()
|
|
49
|
+
bibtex_format.indent = self.bibtex_format_indent
|
|
50
|
+
bibtex_format.block_separator = self.bibtex_format_block_separator
|
|
51
|
+
bibtex_format.trailing_comma = self.bibtex_format_trailing_comma
|
|
52
|
+
self.bibtex_format: Optional[BibtexFormat] = bibtex_format
|
|
53
|
+
|
|
54
|
+
self._python_bib = PythonRunBib(self.options)
|
|
55
|
+
|
|
56
|
+
def write_to_str(self, library: Union[Library, List[Block]]) -> List[str]:
|
|
57
|
+
"""Serialize a BibTeX database to a string.
|
|
58
|
+
|
|
59
|
+
Args:
|
|
60
|
+
library (Library | List[Block]): BibTeX database to serialize.
|
|
61
|
+
bibtex_format (Optional[BibtexFormat] = None):
|
|
62
|
+
|
|
63
|
+
"""
|
|
64
|
+
return ConvertLibrayToStr(self.options).generate_str(library, self.bibtex_format)
|
|
65
|
+
|
|
66
|
+
def write_to_file(
|
|
67
|
+
self,
|
|
68
|
+
original_data: Union[Library, List[Block], List[str]],
|
|
69
|
+
file_name: str,
|
|
70
|
+
write_flag: str = "w",
|
|
71
|
+
path_storage: Optional[str] = None,
|
|
72
|
+
check: bool = True,
|
|
73
|
+
delete_first_empty: bool = True,
|
|
74
|
+
delete_last_empty: bool = True,
|
|
75
|
+
compulsory: bool = False,
|
|
76
|
+
delete_original_file: bool = False,
|
|
77
|
+
) -> None:
|
|
78
|
+
"""Write.
|
|
79
|
+
|
|
80
|
+
Args:
|
|
81
|
+
original_data (Union[Library, List[Block], List[str]]): data
|
|
82
|
+
file_name (str): file name
|
|
83
|
+
write_flag (str = "w"): write flag
|
|
84
|
+
path_storage (Optional[str] = None): path storage
|
|
85
|
+
check (bool = True): check
|
|
86
|
+
delete_first_empty (bool = True): delete first empty
|
|
87
|
+
delete_last_empty (bool = True): delete last empty
|
|
88
|
+
compulsory (bool = False): compulsory
|
|
89
|
+
delete_original_file (bool = False): delete original file
|
|
90
|
+
bibtex_format (Optional[BibtexFormat] = None):
|
|
91
|
+
|
|
92
|
+
"""
|
|
93
|
+
_options = {}
|
|
94
|
+
_options.update(self.options)
|
|
95
|
+
_library_str = ConvertLibrayToStr(_options)
|
|
96
|
+
|
|
97
|
+
if isinstance(original_data, Library):
|
|
98
|
+
data_list = _library_str.generate_str(original_data, self.bibtex_format)
|
|
99
|
+
elif isinstance(original_data, list):
|
|
100
|
+
if all([isinstance(line, str) for line in original_data]):
|
|
101
|
+
data_list = [line for line in original_data if isinstance(line, str)]
|
|
102
|
+
else:
|
|
103
|
+
data_list = [line for line in original_data if isinstance(line, Block)]
|
|
104
|
+
data_list = _library_str.generate_str(data_list, self.bibtex_format)
|
|
105
|
+
|
|
106
|
+
write_list(
|
|
107
|
+
data_list,
|
|
108
|
+
file_name,
|
|
109
|
+
write_flag,
|
|
110
|
+
path_storage,
|
|
111
|
+
check,
|
|
112
|
+
delete_first_empty,
|
|
113
|
+
delete_last_empty,
|
|
114
|
+
compulsory,
|
|
115
|
+
delete_original_file,
|
|
116
|
+
)
|
|
117
|
+
return None
|
|
118
|
+
|
|
119
|
+
def write_multi_library_to_file(
|
|
120
|
+
self,
|
|
121
|
+
path_output: str,
|
|
122
|
+
bib_for_abbr: Union[Library, List[Block]],
|
|
123
|
+
bib_for_zotero: Union[Library, List[Block]],
|
|
124
|
+
bib_for_save: Union[Library, List[Block]],
|
|
125
|
+
given_cite_keys: List[str] = [],
|
|
126
|
+
**kwargs,
|
|
127
|
+
) -> Tuple[str, str, str]:
|
|
128
|
+
_options = {}
|
|
129
|
+
_options.update(self.options)
|
|
130
|
+
_options["keep_entries_by_cite_keys"] = given_cite_keys
|
|
131
|
+
_options["sort_entries_by_cite_keys"] = given_cite_keys
|
|
132
|
+
|
|
133
|
+
bib_abbr = ConvertLibrayToStr(_options).generate_str(bib_for_abbr, **kwargs)
|
|
134
|
+
write_list(bib_abbr, self.bib_for_abbr_name, "w", path_output, False, **kwargs)
|
|
135
|
+
|
|
136
|
+
bib_zotero = ConvertLibrayToStr(_options).generate_str(bib_for_zotero, **kwargs)
|
|
137
|
+
write_list(bib_zotero, self.bib_for_zotero_name, "w", path_output, False, **kwargs)
|
|
138
|
+
|
|
139
|
+
bib_save = ConvertLibrayToStr(_options).generate_str(bib_for_save, **kwargs)
|
|
140
|
+
write_list(bib_save, self.bib_for_save_name, "w", path_output, False, **kwargs)
|
|
141
|
+
|
|
142
|
+
full_bib_for_abbr = os.path.join(path_output, self.bib_for_abbr_name)
|
|
143
|
+
full_bib_for_zotero = os.path.join(path_output, self.bib_for_zotero_name)
|
|
144
|
+
full_bib_for_save = os.path.join(path_output, self.bib_for_save_name)
|
|
145
|
+
return full_bib_for_abbr, full_bib_for_zotero, full_bib_for_save
|
|
146
|
+
|
|
147
|
+
def output_key_url_http_bib_dict(self, library: Library) -> Dict[str, List[List[str]]]:
|
|
148
|
+
_options = {}
|
|
149
|
+
_options.update(self.options)
|
|
150
|
+
_options["empty_entry_cite_keys"] = True
|
|
151
|
+
|
|
152
|
+
key_url_http_bib_dict: Dict[str, List[List[str]]] = {}
|
|
153
|
+
|
|
154
|
+
for key, entry in library.entries_dict.items():
|
|
155
|
+
|
|
156
|
+
url = entry["url"] if "url" in entry else ""
|
|
157
|
+
if len(url) == 0:
|
|
158
|
+
url = entry["doi"] if "doi" in entry else ""
|
|
159
|
+
if (len(url) != 0) and (not re.match(r"https*://", url)):
|
|
160
|
+
url = f"https://doi.org/{url}"
|
|
161
|
+
|
|
162
|
+
link_list = self._generate_link_list(entry)
|
|
163
|
+
patch_bib = ConvertLibrayToStr(_options).generate_str([entry])
|
|
164
|
+
|
|
165
|
+
v: List[List[str]] = [[], [], patch_bib]
|
|
166
|
+
|
|
167
|
+
if len(url) != 0:
|
|
168
|
+
v[0] = [url + "\n"]
|
|
169
|
+
link_list.insert(0, rf"[www]({url})")
|
|
170
|
+
|
|
171
|
+
join_link = []
|
|
172
|
+
if link_list:
|
|
173
|
+
for i in range(len(link_list) - 1):
|
|
174
|
+
join_link.append(link_list[i].strip() + " |\n")
|
|
175
|
+
join_link.append(link_list[-1].strip() + "\n")
|
|
176
|
+
|
|
177
|
+
join_link[0] = "(" + join_link[0]
|
|
178
|
+
join_link[-1] = join_link[-1].strip() + ")\n"
|
|
179
|
+
|
|
180
|
+
v[1] = join_link
|
|
181
|
+
|
|
182
|
+
key_url_http_bib_dict.update({key: v})
|
|
183
|
+
return key_url_http_bib_dict
|
|
184
|
+
|
|
185
|
+
def _generate_link_list(self, entry) -> List[str]:
|
|
186
|
+
title = entry["title"] if "title" in entry else ""
|
|
187
|
+
if not title:
|
|
188
|
+
return []
|
|
189
|
+
|
|
190
|
+
title = re.sub(r"\s+", "+", title)
|
|
191
|
+
url_google = f"https://scholar.google.com/scholar?q={title}"
|
|
192
|
+
url_connected = f"https://www.connectedpapers.com/search?q={title}"
|
|
193
|
+
url_scite = f"https://scite.ai/search?q={title}"
|
|
194
|
+
|
|
195
|
+
# Search cited number
|
|
196
|
+
cited_number = entry["annotation"] if "annotation" in entry else ""
|
|
197
|
+
if cited_number:
|
|
198
|
+
cited_number = re.sub(r"[^0-9]+", "", cited_number)
|
|
199
|
+
cited_number = int(cited_number) if cited_number.isdigit() else ""
|
|
200
|
+
google = f"[Google Scholar: {cited_number}]({url_google})"
|
|
201
|
+
else:
|
|
202
|
+
google = f"[Google Scholar]({url_google})"
|
|
203
|
+
|
|
204
|
+
connected = f"[Connected Papers]({url_connected})"
|
|
205
|
+
scite = f"[Scite]({url_scite})"
|
|
206
|
+
|
|
207
|
+
link_list = []
|
|
208
|
+
for i, j in zip(["google", "connected", "scite"], [google, connected, scite]):
|
|
209
|
+
if i in self.display_google_connected_scite:
|
|
210
|
+
link_list.append(j)
|
|
211
|
+
|
|
212
|
+
return link_list
|
pyeasyphd/pyeasyphd.py
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import os
|
|
2
|
+
|
|
3
|
+
import sublime
|
|
4
|
+
import sublime_plugin
|
|
5
|
+
from pyadvtools import IterateUpdateDict
|
|
6
|
+
|
|
7
|
+
from pyeasyphd.tools.py_run_bib_md_tex import PyRunBibMdTex
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def delete_files(path_storage: str, extensions) -> None:
|
|
11
|
+
"""Delete."""
|
|
12
|
+
for name in os.listdir(path_storage):
|
|
13
|
+
for ext in extensions:
|
|
14
|
+
if name.endswith(ext) and os.path.isfile(os.path.join(path_storage, name)):
|
|
15
|
+
os.remove(os.path.join(path_storage, name))
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class PypapersCommand(sublime_plugin.WindowCommand):
|
|
19
|
+
def run(self, template="Paper", output_level="next", delete_cache=False):
|
|
20
|
+
vars_dict = self.window.extract_variables()
|
|
21
|
+
|
|
22
|
+
packages_path = vars_dict["packages"]
|
|
23
|
+
|
|
24
|
+
# settings
|
|
25
|
+
options, default_settings, user_settings, project_settings = {}, {}, {}, {}
|
|
26
|
+
file_default_settings = os.path.join(packages_path, "pypapers", "pypapers.sublime-settings")
|
|
27
|
+
if os.path.exists(file_default_settings):
|
|
28
|
+
default_settings = sublime.decode_value(open(file_default_settings).read())
|
|
29
|
+
|
|
30
|
+
file_user_settings = os.path.join(packages_path, "User", "PyPapers.sublime-settings")
|
|
31
|
+
if os.path.exists(file_user_settings):
|
|
32
|
+
user_settings = sublime.decode_value(open(file_user_settings).read())
|
|
33
|
+
|
|
34
|
+
project_settings = self.window.project_data().get("settings", {})
|
|
35
|
+
|
|
36
|
+
iter_update_dict = IterateUpdateDict()
|
|
37
|
+
options = iter_update_dict.dict_update(options, default_settings)
|
|
38
|
+
options = iter_update_dict.dict_update(options, user_settings)
|
|
39
|
+
options = iter_update_dict.dict_update(options, project_settings)
|
|
40
|
+
|
|
41
|
+
# update
|
|
42
|
+
for key in vars_dict:
|
|
43
|
+
if isinstance(vars_dict[key], str):
|
|
44
|
+
os.environ[key] = vars_dict[key]
|
|
45
|
+
|
|
46
|
+
for key in options:
|
|
47
|
+
if isinstance(options[key], str):
|
|
48
|
+
options[key] = os.path.expandvars(os.path.expanduser(options[key]))
|
|
49
|
+
|
|
50
|
+
if delete_cache:
|
|
51
|
+
file_path = vars_dict['file_path']
|
|
52
|
+
|
|
53
|
+
if latex_clean_file_types := options.get('latex_clean_file_types', []):
|
|
54
|
+
postfix = latex_clean_file_types
|
|
55
|
+
else:
|
|
56
|
+
postfix = ['.aux', '.bbl', '.bcf', '.blg', '.fdb_latexmk', '.fls', '.log', '.out', '.run.xml']
|
|
57
|
+
postfix.extend(['.synctex.gz', '.gz', '.nav', '.snm', '.toc', '.xdv'])
|
|
58
|
+
|
|
59
|
+
delete_files(file_path, postfix)
|
|
60
|
+
delete_files(os.path.dirname(file_path), postfix)
|
|
61
|
+
|
|
62
|
+
else:
|
|
63
|
+
# main
|
|
64
|
+
path_output = options.get("path_output", "")
|
|
65
|
+
if len(path_output.strip()) == 0:
|
|
66
|
+
path_output = vars_dict["file_path"]
|
|
67
|
+
|
|
68
|
+
p_r_l_m = PyRunBibMdTex(path_output, vars_dict["file_extension"], template, options)
|
|
69
|
+
p_r_l_m.run_files([vars_dict["file"]], vars_dict["file_base_name"], output_level)
|
|
70
|
+
|
|
71
|
+
# display
|
|
72
|
+
self.window.status_message('Successful.')
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
{
|
|
2
|
+
// config
|
|
3
|
+
// config path
|
|
4
|
+
"path_config": "",
|
|
5
|
+
|
|
6
|
+
// figures, templates, bibs
|
|
7
|
+
"path_bibs": "",
|
|
8
|
+
"path_figures": "",
|
|
9
|
+
"path_templates": "",
|
|
10
|
+
|
|
11
|
+
// pypapers/bib/core/convert_str_to_str.py
|
|
12
|
+
"default_additional_field_list": [],
|
|
13
|
+
|
|
14
|
+
// pypapers/bib/bibtexparser/middlewares_str_to_str.py
|
|
15
|
+
"substitute_in_bib": true,
|
|
16
|
+
"substitute_old_list": [],
|
|
17
|
+
"substitute_new_list": [],
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
// pypapers/bib/core/convert_str_to_library.py
|
|
21
|
+
"is_standardize_bib": true,
|
|
22
|
+
|
|
23
|
+
// pypapers/bib/bibtexparser/middlewares_str_to_library.py
|
|
24
|
+
"is_display_implicit_comments": true,
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
// pypapers/bib/core/convert_library_to_library.py
|
|
28
|
+
// "abbr", "zotero", or "save"
|
|
29
|
+
"choose_abbr_zotero_save": "save",
|
|
30
|
+
|
|
31
|
+
// pypapers/bib/bibtexparser/middlewares_library_to_library.py
|
|
32
|
+
"function_common_again": true,
|
|
33
|
+
"function_common_again_abbr": true,
|
|
34
|
+
"function_common_again_zotero": true,
|
|
35
|
+
"function_common_again_save": true,
|
|
36
|
+
// "is_sort_entry_fields": false,
|
|
37
|
+
// "is_sort_blocks": false,
|
|
38
|
+
// "sort_entries_by_cite_keys": [],
|
|
39
|
+
// "sort_entries_by_field_keys": ["year", "volume", "number", "month", "pages"],
|
|
40
|
+
// "sort_entries_by_field_keys_reverse": false,
|
|
41
|
+
|
|
42
|
+
// for common
|
|
43
|
+
"lower_entry_type": true,
|
|
44
|
+
"lower_entry_field_key": true,
|
|
45
|
+
"keep_entries_by_cite_keys": [],
|
|
46
|
+
"update_month_year": true,
|
|
47
|
+
"update_number_volume": true,
|
|
48
|
+
"update_pages": true,
|
|
49
|
+
"update_title": true,
|
|
50
|
+
"sentence_title_case": true,
|
|
51
|
+
"generate_entry_cite_keys": false,
|
|
52
|
+
"full_abbr_article_dict": {},
|
|
53
|
+
"full_abbr_inproceedings_dict": {},
|
|
54
|
+
"full_names_in_json": "names_full",
|
|
55
|
+
"abbr_names_in_json": "names_abbr",
|
|
56
|
+
|
|
57
|
+
// special for abbr
|
|
58
|
+
// abbreviate
|
|
59
|
+
"full_to_abbr_for_abbr": true,
|
|
60
|
+
// 0, 1, 2
|
|
61
|
+
"abbr_index_article_for_abbr": 1,
|
|
62
|
+
"abbr_index_inproceedings_for_abbr": 2,
|
|
63
|
+
|
|
64
|
+
// format doi and url
|
|
65
|
+
// keep only doi or url
|
|
66
|
+
"doi_or_url_for_abbr": true,
|
|
67
|
+
// change doi to url format (https://doi.org/xxx)
|
|
68
|
+
"doi_to_url_for_abbr": true,
|
|
69
|
+
// add link to fields
|
|
70
|
+
"add_link_to_fields_for_abbr": null,
|
|
71
|
+
|
|
72
|
+
// keep some fields for abbr
|
|
73
|
+
// true, false
|
|
74
|
+
"keep_fields_for_abbr": true,
|
|
75
|
+
"keep_entry_list_for_abbr": ["article", "inproceedings", "incollection", "misc", "book", "phdthesis", "mastersthesis", "techreport"],
|
|
76
|
+
"keep_field_list_list_for_abbr": [
|
|
77
|
+
["author", "title", "year", "month", "journal", "pages", "volume", "number", "doi", "url", "annotation"],
|
|
78
|
+
["author", "title", "year", "month", "booktitle", "pages", "doi", "url", "annotation"],
|
|
79
|
+
["author", "title", "year", "month", "booktitle", "pages", "publisher", "doi", "url", "annotation"],
|
|
80
|
+
["author", "title", "year", "month", "publisher", "howpublished", "pages", "doi", "url", "annotation"],
|
|
81
|
+
["author", "title", "year", "month", "publisher", "edition", "doi", "url", "annotation"],
|
|
82
|
+
["author", "title", "year", "month", "type", "school", "address", "pages", "doi", "url", "annotation"],
|
|
83
|
+
["author", "title", "year", "month", "type", "school", "address", "pages", "doi", "url", "annotation"],
|
|
84
|
+
["author", "title", "year", "month", "type", "institution", "address", "pages", "doi", "url", "annotation"],
|
|
85
|
+
],
|
|
86
|
+
|
|
87
|
+
// delete fields list for abbr
|
|
88
|
+
"delete_fields_list_for_abbr": [],
|
|
89
|
+
|
|
90
|
+
// replace some fields for abbr
|
|
91
|
+
"replace_fields_for_abbr": true,
|
|
92
|
+
"replace_old_field_list_for_abbr": [["publisher"]],
|
|
93
|
+
"replace_new_field_list_for_abbr": [["howpublished"]],
|
|
94
|
+
"replace_entry_list_for_abbr": ["misc"],
|
|
95
|
+
// constrain the number of authors for abbr
|
|
96
|
+
"maximum_authors_for_abbr": 0,
|
|
97
|
+
|
|
98
|
+
// special for zotero
|
|
99
|
+
// format doi and url
|
|
100
|
+
"doi_or_url_for_zotero": true,
|
|
101
|
+
|
|
102
|
+
// keep some fields for zotero
|
|
103
|
+
// true, false
|
|
104
|
+
"keep_fields_for_zotero": true,
|
|
105
|
+
"keep_entry_list_for_zotero": ["article", "inproceedings", "incollection", "misc", "book", "phdthesis", "mastersthesis", "techreport"],
|
|
106
|
+
"keep_field_list_list_for_zotero": [
|
|
107
|
+
["abstract", "author", "title", "year", "month", "journal", "pages", "volume", "number", "doi", "url", "annotation"],
|
|
108
|
+
["abstract", "author", "title", "year", "month", "booktitle", "pages", "doi", "url", "annotation"],
|
|
109
|
+
["abstract", "author", "title", "year", "month", "booktitle", "pages", "publisher", "doi", "url", "annotation"],
|
|
110
|
+
["abstract", "author", "title", "year", "month", "publisher", "pages", "doi", "url", "annotation"],
|
|
111
|
+
["abstract", "author", "title", "year", "month", "publisher", "edition", "doi", "url", "annotation"],
|
|
112
|
+
["abstract", "author", "title", "year", "month", "type", "school", "address", "pages", "doi", "url", "annotation"],
|
|
113
|
+
["abstract", "author", "title", "year", "month", "type", "school", "address", "pages", "doi", "url", "annotation"],
|
|
114
|
+
["abstract", "author", "title", "year", "month", "type", "institution", "address", "pages", "doi", "url", "annotation"],
|
|
115
|
+
],
|
|
116
|
+
|
|
117
|
+
// delete fields list for zotero
|
|
118
|
+
"delete_fields_list_for_zotero": [],
|
|
119
|
+
|
|
120
|
+
// delete redundant in `journal` or `booktitle`
|
|
121
|
+
"delete_redundant_in_journal_booktitle": true,
|
|
122
|
+
|
|
123
|
+
// title (lower, upper) journal and booktitle
|
|
124
|
+
"title_journal_booktitle_for_zotero": true,
|
|
125
|
+
|
|
126
|
+
// add field 'archive'.
|
|
127
|
+
"add_archive_for_zotero": true,
|
|
128
|
+
|
|
129
|
+
// add field 'journal abbreviation'.
|
|
130
|
+
"add_journal_abbr_for_zotero": true,
|
|
131
|
+
|
|
132
|
+
// special for save
|
|
133
|
+
// delete fields list for save
|
|
134
|
+
"delete_fields_list_for_save": [],
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
// pypapers/bib/core/convert_library_to_str.py
|
|
138
|
+
"is_standardize_library": false,
|
|
139
|
+
"empty_entry_cite_keys": false,
|
|
140
|
+
"add_index_to_entries": false,
|
|
141
|
+
"entries_necessary": true,
|
|
142
|
+
|
|
143
|
+
// pypapers/bib/bibtexparser/middlewares_library_to_str.py
|
|
144
|
+
"is_sort_entry_fields": true,
|
|
145
|
+
"is_sort_blocks": true,
|
|
146
|
+
"sort_entries_by_cite_keys": [],
|
|
147
|
+
"sort_entries_by_field_keys": ["year", "volume", "number", "month", "pages"],
|
|
148
|
+
"sort_entries_by_field_keys_reverse": true,
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
// pypapers/main/pandoc_md_to.py
|
|
152
|
+
// for pandoc
|
|
153
|
+
"csl_name": "apa-no-ampersand",
|
|
154
|
+
// the number of columns in md files
|
|
155
|
+
"columns_in_md": 120,
|
|
156
|
+
// display one line reference note
|
|
157
|
+
"google_connected_paper_scite": true,
|
|
158
|
+
"display_one_line_reference_note": false,
|
|
159
|
+
// "fullcite", "cite"
|
|
160
|
+
"cite_flag_in_tex": "cite",
|
|
161
|
+
|
|
162
|
+
// for bib file
|
|
163
|
+
// pypapers/main/python_writers.py
|
|
164
|
+
// "abbr.bib", "zotero.bib", "save.bib"
|
|
165
|
+
"bib_for_abbr_name": "abbr.bib",
|
|
166
|
+
"bib_for_zotero_name": "zotero.bib",
|
|
167
|
+
"bib_for_save_name": "save.bib",
|
|
168
|
+
// "choose_abbr_zotero_save": "save",
|
|
169
|
+
// choose multiple items ["google", "connected", "scite"]
|
|
170
|
+
"display_google_connected_scite": ["google", "connected", "scite"],
|
|
171
|
+
// bib format
|
|
172
|
+
"bibtex_format_indent": " ",
|
|
173
|
+
"bibtex_format_trailing_comma": true,
|
|
174
|
+
"bibtex_format_block_separator": "",
|
|
175
|
+
|
|
176
|
+
// for md file
|
|
177
|
+
// pypapers/main/python_run_md.py
|
|
178
|
+
// default is ""
|
|
179
|
+
"final_output_main_md_name": "",
|
|
180
|
+
// true, false
|
|
181
|
+
"delete_temp_generate_md": true,
|
|
182
|
+
// add reference to markdown files
|
|
183
|
+
"add_reference_in_md": true,
|
|
184
|
+
// add bib to markdown files
|
|
185
|
+
"add_bib_in_md": false,
|
|
186
|
+
// true, false
|
|
187
|
+
"replace_cite_to_fullcite_in_md": false,
|
|
188
|
+
// basic, beauty, complex
|
|
189
|
+
"replace_by_basic_beauty_complex_in_md": "beauty",
|
|
190
|
+
// basic, beauty, complex
|
|
191
|
+
"display_basic_beauty_complex_references_in_md": "beauty",
|
|
192
|
+
|
|
193
|
+
// for tex file
|
|
194
|
+
// pypapers/main/python_run_tex.py
|
|
195
|
+
// handly preamble
|
|
196
|
+
"handly_preamble": false,
|
|
197
|
+
|
|
198
|
+
// default is ""
|
|
199
|
+
"final_output_main_tex_name": "",
|
|
200
|
+
// true, false
|
|
201
|
+
"run_latex": false,
|
|
202
|
+
// "pdflatex", "xelatex"
|
|
203
|
+
"pdflatex_xelatex": "pdflatex",
|
|
204
|
+
// true, false
|
|
205
|
+
"delete_run_latex_cache": true,
|
|
206
|
+
"latex_clean_file_types": [
|
|
207
|
+
".aux", ".bbl", ".bcf", ".blg", ".fdb_latexmk", ".fls", ".log", ".out", ".run.xml", ".synctex.gz", ".gz",
|
|
208
|
+
".nav", ".snm", ".toc", ".xdv"
|
|
209
|
+
],
|
|
210
|
+
|
|
211
|
+
// pypapers/tools/python_run_latex_md.py
|
|
212
|
+
// true, false
|
|
213
|
+
"generate_html": false,
|
|
214
|
+
|
|
215
|
+
// true, false
|
|
216
|
+
"generate_tex": true,
|
|
217
|
+
|
|
218
|
+
// ture, false
|
|
219
|
+
"shutil_figures": true,
|
|
220
|
+
|
|
221
|
+
// for figure, bib, tex, and md
|
|
222
|
+
"figure_folder_name": "fig", // "" or "figs" or "main"
|
|
223
|
+
"bib_folder_name": "bib", // "" or "bibs" or "main"
|
|
224
|
+
"md_folder_name": "md", // "" or "mds" or "main"
|
|
225
|
+
"tex_folder_name": "tex", // "" or "texes" or "main"
|
|
226
|
+
|
|
227
|
+
// for delete original md, tex, and bib files in output folder
|
|
228
|
+
"delete_original_md_in_output_folder": false,
|
|
229
|
+
"delete_original_tex_in_output_folder": false,
|
|
230
|
+
"delete_original_bib_in_output_folder": false,
|
|
231
|
+
|
|
232
|
+
// pypapers/pypapers.py
|
|
233
|
+
// default is the same with the active file
|
|
234
|
+
"path_output": "",
|
|
235
|
+
}
|