pyeasyphd 0.4.42__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.
Files changed (53) hide show
  1. pyeasyphd/.python-version +1 -0
  2. pyeasyphd/Main.sublime-menu +43 -0
  3. pyeasyphd/__init__.py +5 -0
  4. pyeasyphd/data/templates/csl/apa-no-ampersand.csl +2183 -0
  5. pyeasyphd/data/templates/csl/apa.csl +2133 -0
  6. pyeasyphd/data/templates/csl/ieee.csl +512 -0
  7. pyeasyphd/data/templates/tex/Article.tex +38 -0
  8. pyeasyphd/data/templates/tex/Article_Header.tex +29 -0
  9. pyeasyphd/data/templates/tex/Article_Tail.tex +3 -0
  10. pyeasyphd/data/templates/tex/Beamer_Header.tex +79 -0
  11. pyeasyphd/data/templates/tex/Beamer_Tail.tex +14 -0
  12. pyeasyphd/data/templates/tex/Style.tex +240 -0
  13. pyeasyphd/data/templates/tex/TEVC_Header.tex +52 -0
  14. pyeasyphd/data/templates/tex/TEVC_Tail.tex +4 -0
  15. pyeasyphd/data/templates/tex/eisvogel.tex +1064 -0
  16. pyeasyphd/data/templates/tex/math.tex +201 -0
  17. pyeasyphd/data/templates/tex/math_commands.tex +677 -0
  18. pyeasyphd/data/templates/tex/nextaimathmacros.sty +681 -0
  19. pyeasyphd/main/__init__.py +6 -0
  20. pyeasyphd/main/basic_input.py +101 -0
  21. pyeasyphd/main/pandoc_md_to.py +380 -0
  22. pyeasyphd/main/python_run_md.py +320 -0
  23. pyeasyphd/main/python_run_tex.py +200 -0
  24. pyeasyphd/pyeasyphd.py +86 -0
  25. pyeasyphd/pyeasyphd.sublime-settings +100 -0
  26. pyeasyphd/pyeasyphd.sublime-syntax +5 -0
  27. pyeasyphd/scripts/__init__.py +34 -0
  28. pyeasyphd/scripts/_base.py +65 -0
  29. pyeasyphd/scripts/run_article_md.py +101 -0
  30. pyeasyphd/scripts/run_article_tex.py +94 -0
  31. pyeasyphd/scripts/run_beamer_tex.py +84 -0
  32. pyeasyphd/scripts/run_compare.py +71 -0
  33. pyeasyphd/scripts/run_format.py +62 -0
  34. pyeasyphd/scripts/run_generate.py +211 -0
  35. pyeasyphd/scripts/run_replace.py +34 -0
  36. pyeasyphd/scripts/run_search.py +251 -0
  37. pyeasyphd/tools/__init__.py +12 -0
  38. pyeasyphd/tools/generate/generate_from_bibs.py +181 -0
  39. pyeasyphd/tools/generate/generate_html.py +166 -0
  40. pyeasyphd/tools/generate/generate_library.py +203 -0
  41. pyeasyphd/tools/generate/generate_links.py +400 -0
  42. pyeasyphd/tools/py_run_bib_md_tex.py +398 -0
  43. pyeasyphd/tools/search/data.py +282 -0
  44. pyeasyphd/tools/search/search_base.py +146 -0
  45. pyeasyphd/tools/search/search_core.py +400 -0
  46. pyeasyphd/tools/search/search_keywords.py +229 -0
  47. pyeasyphd/tools/search/search_writers.py +350 -0
  48. pyeasyphd/tools/search/utils.py +190 -0
  49. pyeasyphd/utils/utils.py +99 -0
  50. pyeasyphd-0.4.42.dist-info/METADATA +33 -0
  51. pyeasyphd-0.4.42.dist-info/RECORD +53 -0
  52. pyeasyphd-0.4.42.dist-info/WHEEL +4 -0
  53. pyeasyphd-0.4.42.dist-info/licenses/LICENSE +674 -0
@@ -0,0 +1,229 @@
1
+ import copy
2
+ import os
3
+ import re
4
+ from pathlib import Path
5
+ from typing import Any
6
+
7
+ from pyadvtools import generate_nested_dict, read_list, standard_path, write_list
8
+ from pybibtexer.tools.experiments_base import generate_standard_publisher_abbr_options_dict
9
+
10
+ from ...main import PandocMdTo
11
+ from ...utils.utils import html_head, html_style, html_tail
12
+ from .data import obtain_search_keywords
13
+ from .search_core import SearchResultsCore
14
+ from .utils import extract_information, temp_html_style
15
+
16
+
17
+ class Searchkeywords:
18
+ """Search keywords in bibliography data.
19
+
20
+ Args:
21
+ path_storage (str): Path to storage directory for journals or conferences.
22
+ path_output (str): Path to output directory for journals or conferences.
23
+ options (dict): Configuration options.
24
+
25
+ Attributes:
26
+ path_storage (str): Path to storage directory.
27
+ path_output (str): Path to output directory.
28
+ options (dict): Configuration options.
29
+ search_year_list (list[str]): list of years to search. Defaults to [].
30
+ """
31
+
32
+ def __init__(self, path_storage: str, path_output: str, options: dict[str, Any]) -> None:
33
+ """Initialize Searchkeywords with storage and output paths.
34
+
35
+ Args:
36
+ path_storage (str): Path to storage directory.
37
+ path_output (str): Path to output directory.
38
+ options (dict[str, Any]): Configuration options.
39
+ """
40
+ self.path_storage = standard_path(path_storage)
41
+ self.path_output = standard_path(path_output)
42
+
43
+ options_ = {}
44
+ options_["display_one_line_reference_note"] = True # default is False
45
+ options_["is_standardize_bib"] = False # default is True
46
+ options_["choose_abbr_zotero_save"] = "save" # default is "save"
47
+ options_["function_common_again"] = True # default is True
48
+ options_["function_common_again_for_abbr"] = False # default is True
49
+ options_["function_common_again_for_zotero"] = False # default is True
50
+ options_["function_common_again_for_save"] = False # default is True
51
+ options_["is_sort_entry_fields"] = True # default is True
52
+ options_["is_sort_blocks"] = True # default is True
53
+ options_["sort_entries_by_field_keys_reverse"] = True # default is True
54
+ options_["generate_entry_cite_keys"] = True # default is True
55
+
56
+ options_["default_keywords_dict"] = obtain_search_keywords()
57
+ options_["default_search_field_list"] = ["title", "abstract"]
58
+ options_.update(options)
59
+ self.options = options_
60
+
61
+ self.search_year_list = options.get("search_year_list", [])
62
+ self._path_separate = self.path_output + "-Separate"
63
+
64
+ self._path_statistic = self.path_output + "-Statistics"
65
+ self._path_combine = self.path_output + "-Combine"
66
+
67
+ def run(self) -> None:
68
+ """Run the keyword search process."""
69
+ all_dict = {}
70
+ publisher_abbr_dict = generate_standard_publisher_abbr_options_dict(self.path_storage, self.options)
71
+ for publisher in publisher_abbr_dict:
72
+ for abbr in publisher_abbr_dict[publisher]:
73
+ options = publisher_abbr_dict[publisher][abbr]
74
+
75
+ path_storage = os.path.join(self.path_storage, publisher, abbr)
76
+ path_output = os.path.join(self.path_output, publisher, abbr)
77
+ entry_type_keyword_type_keyword_field_number_dict = SearchResultsCore(
78
+ path_storage, path_output, self._path_separate, abbr, options
79
+ ).optimize(copy.deepcopy(self.search_year_list))
80
+
81
+ all_dict.update({abbr: entry_type_keyword_type_keyword_field_number_dict})
82
+
83
+ if not self.options.get("print_on_screen", False):
84
+ extract_information(all_dict, self._path_statistic)
85
+
86
+ print()
87
+ self._generate_bib_html_for_publisher(publisher_abbr_dict, "bib")
88
+ print()
89
+ self._generate_bib_html_for_publisher(publisher_abbr_dict, "html")
90
+ self._generate_link_to_bib_html_for_combine()
91
+
92
+ print()
93
+ self._pandoc_md_to_html_in_path_separate()
94
+ self._generate_link_to_html_bib_for_separate()
95
+
96
+ return None
97
+
98
+ def _extract_files(
99
+ self, publisher_abbr_dict: dict, ext: str = "html"
100
+ ) -> dict[str, dict[str, dict[str, dict[str, list[str]]]]]:
101
+ data_dict = {}
102
+ for publisher in publisher_abbr_dict:
103
+ for abbr in publisher_abbr_dict[publisher]:
104
+ p = os.path.join(self.path_output, publisher, abbr)
105
+ if not os.path.exists(p):
106
+ continue
107
+
108
+ for entry_type in [f for f in os.listdir(p) if os.path.isdir(os.path.join(p, f))]:
109
+ if not (folders := [f for f in os.listdir(os.path.join(p, entry_type)) if "combine" in f.lower()]):
110
+ continue
111
+
112
+ for root, _, files in os.walk(os.path.join(p, entry_type, folders[0])):
113
+ for file in [f for f in files if f.endswith(ext)]:
114
+ (
115
+ data_dict.setdefault(file, {})
116
+ .setdefault(entry_type, {})
117
+ .setdefault(publisher, {})
118
+ .setdefault(abbr, [])
119
+ .append(os.path.join(root, file))
120
+ )
121
+ return data_dict
122
+
123
+ def _generate_bib_html_for_publisher(self, publisher_abbr_dict, ext: str = "html") -> None:
124
+ data_dict = self._extract_files(publisher_abbr_dict, ext)
125
+ for file in data_dict:
126
+ basename = file.split(".")[0]
127
+ for entry_type in data_dict[file]:
128
+ for publisher in data_dict[file][entry_type]:
129
+ print(f"Generate {ext} for `{publisher}-{entry_type}-{basename}`")
130
+ data_list = []
131
+ for abbr in data_dict[file][entry_type][publisher]:
132
+ for i in range(ll := len(data_dict[file][entry_type][publisher][abbr])):
133
+ full_file = data_dict[file][entry_type][publisher][abbr][i]
134
+ temp_data_list = read_list(full_file, "r", None)
135
+ if ext == "html":
136
+ if mch := re.search(r"(<h3.*)</body>", "".join(temp_data_list), re.DOTALL):
137
+ temp_data_list = mch.group(1).splitlines(keepends=True)
138
+
139
+ data_list.extend(temp_data_list)
140
+ if i < (ll - 1):
141
+ data_list.append("\n")
142
+ data_list.append("\n")
143
+
144
+ p = os.path.join(self._path_combine, entry_type, publisher, ext)
145
+ if ext == "html":
146
+ data_list_ = [html_head.format(basename)]
147
+ data_list_.extend(html_style)
148
+ data_list_.append(f'<h2 id="{publisher.upper()}">{publisher.upper()}</h2>\n')
149
+ data_list_.extend(data_list)
150
+ data_list_.append(html_tail)
151
+ write_list(data_list_, f"{basename}.{ext}", "w", p, False)
152
+
153
+ else:
154
+ write_list(data_list, f"{basename}.{ext}", "w", p, False)
155
+ return None
156
+
157
+ def _generate_link_to_bib_html_for_combine(self) -> None:
158
+ nested_dict = generate_nested_dict(self._path_combine)
159
+
160
+ for entry_type in nested_dict:
161
+ data_dict = {}
162
+ for publisher in nested_dict[entry_type]:
163
+ for ext in nested_dict[entry_type][publisher]:
164
+ if ext == "html":
165
+ for file in nested_dict[entry_type][publisher][ext]:
166
+ data_dict.setdefault(publisher, []).append(file)
167
+
168
+ if ext == "bib":
169
+ for file in nested_dict[entry_type][publisher][ext]:
170
+ if not re.search(r"\-zotero", file):
171
+ continue
172
+
173
+ data_dict.setdefault(publisher, []).append(file)
174
+
175
+ data_list = self._html_format(entry_type, data_dict, "Publishers", "combine")
176
+ write_list(data_list, f"{entry_type.lower()}_links.html", "w", self._path_combine, False)
177
+ return None
178
+
179
+ def _pandoc_md_to_html_in_path_separate(self) -> None:
180
+ mds = []
181
+ for root, _, files in os.walk(self._path_separate):
182
+ mds.extend([os.path.join(root, f) for f in files if f.endswith(".md")])
183
+
184
+ for full_md in mds:
185
+ print(f"pandoc md to html for `{full_md.split(self._path_separate)[-1]}`")
186
+ full_html = full_md.replace("-md", "-html").replace(".md", ".html")
187
+ PandocMdTo({}).pandoc_md_to_html(full_md, full_html, None, None, True)
188
+
189
+ def _generate_link_to_html_bib_for_separate(self) -> None:
190
+ for entry_type in (nested_dict := generate_nested_dict(self._path_separate)):
191
+ data_dict = {}
192
+ for keywords_type in nested_dict[entry_type]:
193
+ for ext in nested_dict[entry_type][keywords_type]:
194
+ if not re.search(r"(\-html\-|\-bib\-zotero)", ext):
195
+ continue
196
+
197
+ for file in nested_dict[entry_type][keywords_type][ext]:
198
+ data_dict.setdefault(os.path.basename(file).split(".")[0], []).append(file)
199
+
200
+ data_list = self._html_format(entry_type, data_dict, "Keywords", "separate")
201
+ write_list(data_list, f"{entry_type.lower()}_links.html", "w", self._path_separate, False)
202
+ return None
203
+
204
+ @staticmethod
205
+ def _html_format(entry_type, data_dict, name_flag, index):
206
+ data_list = [html_head.format(f"{entry_type.title()} Links"), temp_html_style]
207
+ data_list.append('\n<table border="1">\n')
208
+ data_list.append(f"<caption>{entry_type.title()} Links</caption>\n")
209
+
210
+ data_list.extend(["<thead>\n", "<tr>\n", f"<th>{name_flag}</th>\n", "</tr>\n", "</thead>\n"])
211
+
212
+ x = '<td><a href="{}" target="_blank">{}</a></td>\n'
213
+ data_list.append("<tbody>\n")
214
+ for name in data_dict:
215
+ data_list.append("<tr>\n")
216
+ data_list.append(f"<td>{name}</td>\n")
217
+
218
+ for f in data_dict[name]:
219
+ folders = Path(f).parts[1:]
220
+ if index == "combine":
221
+ data_list.append(x.format(f, folders[-1].split("-")[0].title() + ":" + f.split(".")[-1]))
222
+ elif index == "separate":
223
+ data_list.append(x.format(f, folders[-2].split("-")[0].title() + ":" + f.split(".")[-1]))
224
+ data_list.append("</tr>\n")
225
+ data_list.append("</tbody>\n")
226
+
227
+ data_list.append("</table>\n")
228
+ data_list.append(html_tail)
229
+ return data_list
@@ -0,0 +1,350 @@
1
+ import copy
2
+ import os
3
+
4
+ from pyadvtools import combine_content_in_list, read_list, write_list
5
+ from pybibtexer.bib.bibtexparser import Library
6
+ from pybibtexer.main import PythonWriters
7
+
8
+ from ...main import BasicInput, PandocMdTo
9
+ from ...tools.search.utils import combine_keywords_for_file_name, combine_keywords_for_title, keywords_type_for_title
10
+
11
+
12
+ class WriteInitialResult(BasicInput):
13
+ """Write initial results for single keyword.
14
+
15
+ Args:
16
+ options (dict): Configuration options.
17
+
18
+ Attributes:
19
+ options (dict): Configuration options.
20
+ """
21
+
22
+ def __init__(self, options: dict) -> None:
23
+ """Initialize WriteInitialResult with configuration options.
24
+
25
+ Args:
26
+ options (dict): Configuration options.
27
+ """
28
+ super().__init__(options)
29
+
30
+ self._level_title_md = "###"
31
+ self._level_title_tex = "subsection"
32
+ self._pandoc_md_to = PandocMdTo(options)
33
+
34
+ def main(
35
+ self,
36
+ path_initial: str,
37
+ output_prefix: str,
38
+ field: str,
39
+ keywords_type: str,
40
+ combine_keywords: str,
41
+ library_for_abbr: Library,
42
+ library_for_zotero: Library,
43
+ library_for_save: Library,
44
+ ) -> tuple[list[list[str]], list[str]]:
45
+ """Main method to write initial results.
46
+
47
+ Args:
48
+ path_initial (str): Path to initial directory.
49
+ output_prefix (str): Prefix for output files.
50
+ field (str): Field being searched.
51
+ keywords_type (str): Type of keywords.
52
+ combine_keywords (str): Combined keywords string.
53
+ library_for_abbr (Library): Abbreviated bibliography library.
54
+ library_for_zotero (Library): Zotero bibliography library.
55
+ library_for_save (Library): Save bibliography library.
56
+
57
+ Returns:
58
+ tuple[list[list[str]], list[str]]: Tuple containing data and error messages.
59
+ """
60
+ error_pandoc_md_md = []
61
+
62
+ # generate
63
+ cite_keys = [entry.key for entry in library_for_abbr.entries]
64
+
65
+ # update options
66
+ _options = copy.deepcopy(self.options)
67
+ _options["keep_entries_by_cite_keys"] = cite_keys
68
+ _python_writer = PythonWriters(_options)
69
+
70
+ # generate tex and md data
71
+ data_list_tex, data_list_md, header = self.generate_content_tex_md(
72
+ cite_keys, output_prefix, field, combine_keywords
73
+ )
74
+
75
+ # definition
76
+ file_prefix = combine_keywords_for_file_name(combine_keywords) # the file name prefix
77
+
78
+ # write tex, md, and bib files
79
+ data_list = [data_list_tex, data_list_md, library_for_abbr, library_for_zotero, library_for_save]
80
+ mid_list = ["", "", "-abbr", "-zotero", "-save"]
81
+ post_list = ["tex", "md", "bib", "bib", "bib"]
82
+ path_write = os.path.join(path_initial, f"{field}-{keywords_type}")
83
+ for i in range(len(post_list)):
84
+ file_name = f"{file_prefix}{mid_list[i]}.{post_list[i]}"
85
+ _python_writer.write_to_file(data_list[i], file_name, "w", path_write)
86
+
87
+ # pandoc md to generate md file
88
+ path_bib = os.path.join(path_write, f"{file_prefix}{mid_list[2]}.bib") # bib_for_abbr
89
+ data_list_pandoc_md = self._pandoc_md_to.pandoc_md_to_md(
90
+ path_bib, path_write, path_write, f"{file_prefix}.md", f"{file_prefix}-pandoc.md"
91
+ )
92
+
93
+ # mian part
94
+ # generate some md output data
95
+ data_basic_md: list[str] = []
96
+ data_beauty_md: list[str] = []
97
+ data_complex_md: list[str] = []
98
+ if data_list_pandoc_md:
99
+ data_basic_md, data_beauty_md, data_complex_md = self.generate_basic_beauty_complex_md(
100
+ header, cite_keys, data_list_pandoc_md, library_for_zotero
101
+ )
102
+ else:
103
+ error_pandoc_md_md.append(f"- pandoc full false: {file_prefix}_pandoc.md" + "\n")
104
+
105
+ # write basic beauty complex md files
106
+ basic_beauty_complex = ["-basic", "-beauty", "-complex"]
107
+ for d, name in zip([data_basic_md, data_beauty_md, data_complex_md], basic_beauty_complex, strict=True):
108
+ write_list(d, f"{file_prefix}{name}.md", "w", path_write)
109
+
110
+ # save all (tex, md, bib) files
111
+ x = [f"{i}.{j}" for i, j in zip(mid_list, post_list, strict=True)]
112
+ x.extend([f"{i}.md" for i in basic_beauty_complex])
113
+ data_temp = [[os.path.join(path_write, file_prefix + i)] for i in x]
114
+ return data_temp, error_pandoc_md_md
115
+
116
+ def generate_basic_beauty_complex_md(
117
+ self, header: str, cite_key_list: list[str], data_list_pandoc_md: list[str], library_for_zotero: Library
118
+ ) -> tuple[list[str], list[str], list[str]]:
119
+ """Generate basic, beauty, and complex markdown content.
120
+
121
+ Args:
122
+ header (str): Header string for the content.
123
+ cite_key_list (list[str]): list of citation keys.
124
+ data_list_pandoc_md (list[str]): list of pandoc markdown data.
125
+ library_for_zotero (Library): Zotero bibliography library.
126
+
127
+ Returns:
128
+ tuple[list[str], list[str], list[str]]: Tuple containing basic, beauty, and complex markdown content.
129
+ """
130
+ data_basic_md, data_beauty_md, data_complex_md = [], [], []
131
+
132
+ # library
133
+ _options = copy.deepcopy(self.options)
134
+ _python_writer = PythonWriters(_options)
135
+ key_url_http_bib_dict = _python_writer.output_key_url_http_bib_dict(library_for_zotero)
136
+
137
+ key_basic_dict, key_beauty_dict, key_complex_dict = self._pandoc_md_to.generate_key_data_dict(
138
+ data_list_pandoc_md, key_url_http_bib_dict
139
+ )
140
+
141
+ if key_basic_dict and key_beauty_dict and key_complex_dict:
142
+ data_basic_md, data_beauty_md, data_complex_md = [header + "\n"], [header + "\n"], [header + "\n"]
143
+ for i in range(length := len(cite_key_list)):
144
+ data_basic_md.extend(self._convert_to_special_list(key_basic_dict.get(cite_key_list[i], [])))
145
+ data_beauty_md.extend(self._convert_to_special_list(key_beauty_dict.get(cite_key_list[i], [])))
146
+ data_complex_md.extend(self._convert_to_special_list(key_complex_dict.get(cite_key_list[i], [])))
147
+ if i < (length - 1):
148
+ data_basic_md.append("\n")
149
+ data_beauty_md.append("\n")
150
+ data_complex_md.append("\n")
151
+ return data_basic_md, data_beauty_md, data_complex_md
152
+
153
+ @staticmethod
154
+ def _convert_to_special_list(data_list: list[str]) -> list[str]:
155
+ """Convert data list to special formatted list.
156
+
157
+ Args:
158
+ data_list (list[str]): list of data strings.
159
+
160
+ Returns:
161
+ list[str]: Formatted list with proper indentation.
162
+ """
163
+ if len(data_list) > 0:
164
+ data_list[0] = "- " + data_list[0]
165
+ for j in range(len(data_list) - 1):
166
+ if data_list[j][-1] == "\n":
167
+ data_list[j + 1] = " " + data_list[j + 1]
168
+ return data_list
169
+
170
+ def generate_content_tex_md(
171
+ self, cite_key_list: list[str], output_prefix: str, field: str, combine_keywords: str
172
+ ) -> tuple[list[str], list[str], str]:
173
+ """Generate LaTeX and markdown content.
174
+
175
+ Args:
176
+ cite_key_list (list[str]): list of citation keys.
177
+ output_prefix (str): Prefix for output files.
178
+ field (str): Field being searched.
179
+ combine_keywords (str): Combined keywords string.
180
+
181
+ Returns:
182
+ tuple[list[str], list[str], str]: Tuple containing LaTeX content, markdown content, and header.
183
+ """
184
+ c_k_f_t = combine_keywords_for_title(combine_keywords)
185
+
186
+ number_references = len(cite_key_list)
187
+ _title = f"{output_prefix} {field} contains {number_references} {c_k_f_t}"
188
+
189
+ tex_header = f"\\{self._level_title_tex}" + "{" + _title + "}\n"
190
+ tex_body = ["\\nocite{" + f"{c_k}" + "}\n" for c_k in cite_key_list]
191
+ tex_tail = "\\printbibliography\n\n\\ifx \\clearPage \\undefined \\else \\clearpage \\fi\n"
192
+ data_list_tex = combine_content_in_list([[tex_header], ["\n"], tex_body, ["\n"], [tex_tail]])
193
+
194
+ md_header = f"{self._level_title_md}" + " " + _title + "\n"
195
+ md_body = [r"- [@" + f"{c_k}" + "]\n" for c_k in cite_key_list]
196
+ data_list_md = combine_content_in_list([[md_header], ["\n"], md_body])
197
+ return data_list_tex, data_list_md, md_header
198
+
199
+
200
+ class WriteSeparateResult:
201
+ """Write separate result for different keyword types."""
202
+
203
+ def __init__(self) -> None:
204
+ """Initialize WriteSeparateResult with title levels."""
205
+ self._level_title_md = "##"
206
+ self._level_title_tex = "section"
207
+
208
+ def main(
209
+ self, data_temp: list[list[str]], field: str, keywords_type: str, combine_keywords: str, path_separate: str
210
+ ) -> None:
211
+ """Main method to write separate results.
212
+
213
+ Args:
214
+ data_temp (list[list[str]]): list of data lists for different file types.
215
+ field (str): Field being processed.
216
+ keywords_type (str): Type of keywords.
217
+ combine_keywords (str): Combined keywords string.
218
+ path_separate (str): Path to separate directory.
219
+ """
220
+ k_t_f_t = keywords_type_for_title(keywords_type)
221
+ _title = f"{field.title()} contains {k_t_f_t}"
222
+
223
+ file_prefix = combine_keywords_for_file_name(combine_keywords) # the file name prefix
224
+ mid_list = ["", "", "-abbr", "-zotero", "-save", "-basic", "-beauty", "-complex"]
225
+ post_list = ["tex", "md", "bib", "bib", "bib", "md", "md", "md"]
226
+
227
+ len_data_temp = len(data_temp) # len(data_temp) = len(mid_list) = len(post_list) = 8
228
+ split_flag = mid_list.index("-abbr")
229
+
230
+ for i in range(split_flag, len_data_temp):
231
+ path_temp = os.path.join(path_separate, f"{keywords_type}", f"{field}-{post_list[i]}{mid_list[i]}")
232
+ full_file = os.path.join(path_temp, rf"{file_prefix}.{post_list[i]}")
233
+ temp_data_list = read_list(data_temp[i][0], "r", None)
234
+ if not os.path.isfile(full_file):
235
+ if post_list[i] == "md":
236
+ temp_data_list.insert(0, f"{self._level_title_md}" + " " + _title + "\n\n")
237
+ elif post_list[i] == "tex":
238
+ temp_data_list.insert(0, f"\\{self._level_title_tex}" + "{" + _title + "}\n\n")
239
+ else:
240
+ temp_data_list.insert(0, "\n")
241
+ write_list(temp_data_list, full_file, "a", None, False, False) # Compulsory `a`
242
+ return None
243
+
244
+
245
+ class WriteAbbrCombinedResults:
246
+ """Write combined results for abbreviations (such as `TEVC`, `PNAS`).
247
+
248
+ Args:
249
+ options (dict): Configuration options.
250
+
251
+ Attributes:
252
+ options (dict): Configuration options.
253
+ pandoc_md_basic_to_pdf (bool): Whether to convert basic markdown to PDF.
254
+ pandoc_md_beauty_to_pdf (bool): Whether to convert beauty markdown to PDF.
255
+ pandoc_md_complex_to_pdf (bool): Whether to convert complex markdown to PDF.
256
+ pandoc_md_basic_to_html (bool): Whether to convert basic markdown to HTML.
257
+ pandoc_md_beauty_to_html (bool): Whether to convert beauty markdown to HTML.
258
+ pandoc_md_complex_to_html (bool): Whether to convert complex markdown to HTML.
259
+ """
260
+
261
+ def __init__(self, options: dict) -> None:
262
+ """Initialize WriteAbbrCombinedResults with configuration options.
263
+
264
+ Args:
265
+ options (dict): Configuration options.
266
+ """
267
+ self.pandoc_md_basic_to_pdf: bool = options.get("pandoc_md_basic_to_pdf", False)
268
+ self.pandoc_md_beauty_to_pdf: bool = options.get("pandoc_md_beauty_to_pdf", False)
269
+ self.pandoc_md_complex_to_pdf: bool = options.get("pandoc_md_complex_to_pdf", False)
270
+ self.pandoc_md_basic_to_html: bool = options.get("pandoc_md_basic_to_html", False)
271
+ self.pandoc_md_beauty_to_html: bool = options.get("pandoc_md_beauty_to_html", False)
272
+ self.pandoc_md_complex_to_html: bool = options.get("pandoc_md_complex_to_html", True)
273
+
274
+ self._level_title_md = "##"
275
+ self._level_title_tex = "section"
276
+ self._pandoc_md_to = PandocMdTo(options)
277
+
278
+ def main(
279
+ self, search_field_list, keywords_type: str, field_data_dict: dict[str, list[list[str]]], path_combine: str
280
+ ) -> tuple[list[str], list[str]]:
281
+ """Main method to write combined results for abbreviations.
282
+
283
+ Args:
284
+ search_field_list: list of search fields.
285
+ keywords_type (str): Type of keywords.
286
+ field_data_dict (dict[str, list[list[str]]]): dictionary containing field data.
287
+ path_combine (str): Path to combine directory.
288
+
289
+ Returns:
290
+ tuple[list[str], list[str]]: Tuple containing error messages for PDF and HTML conversion.
291
+ """
292
+ path_subsection = os.path.join(path_combine, "tex-subsection")
293
+ path_md = os.path.join(path_combine, "md")
294
+ path_bib = os.path.join(path_combine, "bib")
295
+
296
+ mid_list = ["", "", "-abbr", "-zotero", "-save", "-basic", "-beauty", "-complex"]
297
+ post_list = ["tex", "md", "bib", "bib", "bib", "md", "md", "md"]
298
+ path_list = [path_subsection, path_md, path_bib, path_bib, path_bib]
299
+ for i in ["-basic", "-beauty", "-complex"]:
300
+ path_list.append(os.path.join(path_combine, f"md{i}"))
301
+ # len(mid_list) == len(post_list) == len(path_list) == 8
302
+
303
+ k_t_f_t = keywords_type_for_title(keywords_type)
304
+
305
+ error_pandoc_md_pdf, error_pandoc_md_html = [], []
306
+ for field in search_field_list:
307
+ if not field_data_dict.get(field):
308
+ continue
309
+
310
+ # write files
311
+ file_prefix = f"{field}-{keywords_type}" # the file name prefix
312
+ _title = f"{field.title()} contains {k_t_f_t}"
313
+
314
+ for j in range(0, len(post_list)):
315
+ temp = combine_content_in_list([read_list(file, "r") for file in field_data_dict[field][j]], ["\n"])
316
+ if post_list[j] == "md":
317
+ temp.insert(0, f"{self._level_title_md}" + " " + _title + "\n\n")
318
+ elif post_list[j] == "tex":
319
+ temp.insert(0, f"\\{self._level_title_tex}" + "{" + _title + "}\n\n")
320
+ write_list(temp, f"{file_prefix}{mid_list[j]}.{post_list[j]}", "w", path_list[j])
321
+
322
+ # generate tex pdf html
323
+ # for tex
324
+ self._pandoc_md_to.generate_tex_content(file_prefix, path_subsection, path_bib, path_combine)
325
+
326
+ # for pdf
327
+ for i in ["basic", "beauty", "complex"]:
328
+ if eval(f"self.pandoc_md_{i}_to_pdf"):
329
+ error_flag_pdf = self._pandoc_md_to.pandoc_md_to_pdf(
330
+ os.path.join(path_combine, f"md-{i}"),
331
+ f"{file_prefix}-{i}.md",
332
+ os.path.join(path_combine, f"pdf-{i}"),
333
+ f"{file_prefix}-{i}.pdf",
334
+ )
335
+ if error_flag_pdf:
336
+ error_pandoc_md_pdf.append(error_flag_pdf)
337
+
338
+ # for html
339
+ for i in ["basic", "beauty", "complex"]:
340
+ if eval(f"self.pandoc_md_{i}_to_html"):
341
+ error_flag_html = self._pandoc_md_to.pandoc_md_to_html(
342
+ os.path.join(path_combine, f"md-{i}"),
343
+ os.path.join(path_combine, f"html-{i}"),
344
+ f"{file_prefix}-{i}.md",
345
+ f"{file_prefix}-{i}.html",
346
+ True,
347
+ )
348
+ if error_flag_html:
349
+ error_pandoc_md_html.append(error_flag_html)
350
+ return error_pandoc_md_pdf, error_pandoc_md_html