pyeasyphd 0.1.2__py3-none-any.whl → 0.1.5__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.

Files changed (41) hide show
  1. pyeasyphd/__init__.py +5 -0
  2. pyeasyphd/data/Templates/CSL/apa-no-ampersand.csl +2183 -0
  3. pyeasyphd/data/Templates/CSL/apa.csl +2133 -0
  4. pyeasyphd/data/Templates/CSL/ieee.csl +512 -0
  5. pyeasyphd/data/Templates/TEX/Article.tex +38 -0
  6. pyeasyphd/data/Templates/TEX/Article_Header.tex +29 -0
  7. pyeasyphd/data/Templates/TEX/Article_Tail.tex +3 -0
  8. pyeasyphd/data/Templates/TEX/Beamer_Header.tex +80 -0
  9. pyeasyphd/data/Templates/TEX/Beamer_Tail.tex +14 -0
  10. pyeasyphd/data/Templates/TEX/Style.tex +249 -0
  11. pyeasyphd/data/Templates/TEX/TEVC_Header.tex +52 -0
  12. pyeasyphd/data/Templates/TEX/TEVC_Tail.tex +4 -0
  13. pyeasyphd/data/Templates/TEX/eisvogel.beamer +700 -0
  14. pyeasyphd/data/Templates/TEX/eisvogel.latex +1040 -0
  15. pyeasyphd/data/Templates/TEX/eisvogel.tex +1064 -0
  16. pyeasyphd/data/Templates/TEX/math.tex +196 -0
  17. pyeasyphd/data/Templates/TEX/math_commands.tex +673 -0
  18. pyeasyphd/main/__init__.py +6 -7
  19. pyeasyphd/main/basic_input.py +59 -77
  20. pyeasyphd/main/pandoc_md_to.py +48 -47
  21. pyeasyphd/main/python_run_md.py +65 -24
  22. pyeasyphd/main/python_run_tex.py +52 -21
  23. pyeasyphd/pyeasyphd.py +20 -6
  24. pyeasyphd/pyeasyphd.sublime-settings +0 -10
  25. pyeasyphd/tools/__init__.py +5 -8
  26. pyeasyphd/tools/generate/generate_from_bibs.py +41 -37
  27. pyeasyphd/tools/generate/generate_html.py +48 -8
  28. pyeasyphd/tools/generate/generate_library.py +39 -26
  29. pyeasyphd/tools/generate/generate_links.py +14 -8
  30. pyeasyphd/tools/py_run_bib_md_tex.py +59 -111
  31. pyeasyphd/tools/search/data.py +12 -48
  32. pyeasyphd/tools/search/search_base.py +37 -10
  33. pyeasyphd/tools/search/search_core.py +108 -38
  34. pyeasyphd/tools/search/search_keywords.py +18 -16
  35. pyeasyphd/tools/search/search_writers.py +94 -32
  36. pyeasyphd/tools/search/utils.py +48 -9
  37. pyeasyphd/utils/utils.py +7 -6
  38. {pyeasyphd-0.1.2.dist-info → pyeasyphd-0.1.5.dist-info}/METADATA +3 -3
  39. pyeasyphd-0.1.5.dist-info/RECORD +43 -0
  40. pyeasyphd-0.1.2.dist-info/RECORD +0 -27
  41. {pyeasyphd-0.1.2.dist-info → pyeasyphd-0.1.5.dist-info}/WHEEL +0 -0
@@ -1,11 +1,10 @@
1
- """Initialization."""
1
+ """Main module for PyEasyPhD core functionality.
2
2
 
3
- __all__ = [
4
- "BasicInput",
5
- "PandocMdTo",
6
- "PythonRunMd",
7
- "PythonRunTex",
8
- ]
3
+ This module contains the core classes for processing academic papers,
4
+ managing bibliographies, and converting between different formats.
5
+ """
6
+
7
+ __all__ = ["BasicInput", "PandocMdTo", "PythonRunMd", "PythonRunTex"]
9
8
 
10
9
  from .basic_input import BasicInput
11
10
  from .pandoc_md_to import PandocMdTo
@@ -1,71 +1,43 @@
1
1
  import os
2
2
  from typing import Any, Dict
3
3
 
4
- from pyadvtools import read_list, standard_path
4
+ from pyadvtools import read_list
5
5
  from pybibtexer.main import BasicInput as BasicInputInPyBibtexer
6
6
 
7
7
 
8
8
  class BasicInput(BasicInputInPyBibtexer):
9
- """Basic input.
9
+ """Basic input class for handling bibliography and template configurations.
10
10
 
11
11
  Args:
12
- options (Dict[str, Any]): Options.
12
+ options (Dict[str, Any]): Configuration options.
13
13
 
14
14
  Attributes:
15
- path_bibs (str): Path bibs.
16
- path_figures (str): Path figures.
17
- path_templates (str): Path templates.
18
-
19
- full_csl_style_pandoc (str): Full path to csl style for pandoc.
15
+ full_json_c (str): Full path to conferences JSON file.
16
+ full_json_j (str): Full path to journals JSON file.
17
+ full_csl_style_pandoc (str): Full path to CSL style for pandoc.
20
18
  full_tex_article_template_pandoc (str): Full path to tex article template for pandoc.
21
- article_template_tex (List[str]): Article template for LaTex.
22
-
23
- article_template_header_tex (List[str]): Article template header for LaTex.
24
- article_template_tail_tex (List[str]): Article template tail for LaTex.
25
- beamer_template_header_tex (List[str]): Beamer template header for LaTex.
26
- beamer_template_tail_tex (List[str]): Beamer template tail for LaTex.
27
- math_commands_tex (List[str]): Tex math commands for LaTex.
28
- usepackages_tex (List[str]): Tex usepackages for LaTex.
29
- handly_preamble (bool): Handly preamble.
30
-
31
- options (Dict[str, Any]): Options.
19
+ full_tex_beamer_template_pandoc (str): Full path to tex beamer template for pandoc.
20
+ article_template_tex (List[str]): Article template for LaTeX.
21
+ article_template_header_tex (List[str]): Article template header for LaTeX.
22
+ article_template_tail_tex (List[str]): Article template tail for LaTeX.
23
+ beamer_template_header_tex (List[str]): Beamer template header for LaTeX.
24
+ beamer_template_tail_tex (List[str]): Beamer template tail for LaTeX.
25
+ math_commands_tex (List[str]): LaTeX math commands.
26
+ usepackages_tex (List[str]): LaTeX usepackages.
27
+ handly_preamble (bool): Whether to handle preamble manually.
28
+ options (Dict[str, Any]): Configuration options.
32
29
  """
33
30
 
34
31
  def __init__(self, options: Dict[str, Any]) -> None:
35
- # The paths of Figures, Bibs, and Templates
36
- self.path_bibs: str = standard_path(options.get("path_bibs", ""))
37
- self.path_figures: str = standard_path(options.get("path_figures", ""))
38
- self.path_templates: str = standard_path(options.get("path_templates", ""))
39
-
40
- # Update
41
- path_config = standard_path(options.get("path_config", ""))
42
- if len(self.path_bibs) == 0:
43
- for folder in [
44
- "bib", "bibs", "Bib", "Bibs", "BIB", "BIBS",
45
- "reference", "references", "Reference", "References", "REFERENCE", "REFERENCES"
46
- ]:
47
- if os.path.exists(p := os.path.join(path_config, folder)):
48
- self.path_bibs = p
49
- break
50
-
51
- if len(self.path_figures) == 0:
52
- for folder in [
53
- "figure", "figures", "Figure", "Figures", "FIGURE", "FIGURES",
54
- "fig", "figs", "Fig", "Figs", "FIG", "FIGS",
55
- ]:
56
- if os.path.exists(p := os.path.join(path_config, folder)):
57
- self.path_figures = p
58
- break
59
-
60
- if len(self.path_templates) == 0:
61
- for folder in ["template", "templates", "Template", "Templates", "TEMPLATE", "TEMPLATES"]:
62
- if os.path.exists(p := os.path.join(path_config, folder)):
63
- self.path_templates = p
64
- break
65
-
66
- full_json_c = os.path.join(self.path_templates, "AbbrFull", "conferences.json")
67
- full_json_j = os.path.join(self.path_templates, "AbbrFull", "journals.json")
68
- super().__init__(full_json_c, full_json_j, options)
32
+ """Initialize BasicInput with configuration options.
33
+
34
+ Args:
35
+ options (Dict[str, Any]): Configuration options dictionary.
36
+ """
37
+ super().__init__(options)
38
+
39
+ current_dir = os.path.dirname(os.path.abspath(__file__))
40
+ self._path_templates = os.path.join(os.path.dirname(current_dir), "data", "Templates")
69
41
 
70
42
  # main
71
43
  self._initialize_pandoc_md_to(options)
@@ -73,31 +45,36 @@ class BasicInput(BasicInputInPyBibtexer):
73
45
 
74
46
  self.options = options
75
47
 
76
- # main
77
48
  def _initialize_pandoc_md_to(self, options: Dict[str, Any]) -> None:
49
+ """Initialize pandoc markdown to other formats configuration.
50
+
51
+ Args:
52
+ options (Dict[str, Any]): Configuration options.
53
+ """
78
54
  csl_name = options.get("csl_name", "apa-no-ampersand")
79
- if len(csl_name) == 0:
55
+ if not isinstance(csl_name, str):
80
56
  csl_name = "apa-no-ampersand"
57
+ self.full_csl_style_pandoc = os.path.join(self._path_templates, "CSL", f"{csl_name}.csl")
58
+ if not os.path.exists(self.full_csl_style_pandoc):
59
+ self.full_csl_style_pandoc = os.path.join(self._path_templates, "CSL", "apa-no-ampersand.csl")
81
60
 
82
- full_csl_style_pandoc = os.path.join(self.path_templates, "CSL", f"{csl_name}.csl")
83
- if (p := options.get("full_csl")) is not None:
84
- full_csl_style_pandoc = p
85
- self.full_csl_style_pandoc = full_csl_style_pandoc
86
-
87
- full_tex_article_template_pandoc = os.path.join(self.path_templates, "TEX", "eisvogel.tex")
88
- if (p := options.get("full_eisvogel")) is not None:
89
- full_tex_article_template_pandoc = p
90
- self.full_tex_article_template_pandoc = full_tex_article_template_pandoc
61
+ self.full_tex_article_template_pandoc = os.path.join(self._path_templates, "TEX", "eisvogel.latex")
62
+ self.full_tex_beamer_template_pandoc = os.path.join(self._path_templates, "TEX", "eisvogel.beamer")
91
63
 
92
- self.article_template_tex = self._try_read_list(options, "TEX", "Article.tex", "full_article")
64
+ self.article_template_tex = self._try_read_list("TEX", "Article.tex")
93
65
 
94
66
  def _initialize_python_run_tex(self, options: Dict[str, Any]) -> None:
95
- self.article_template_header_tex = self._try_read_list(options, "TEX", "Article_Header.tex", "full_article_header")
96
- self.article_template_tail_tex = self._try_read_list(options, "TEX", "Article_Tail.tex", "full_article_tail")
97
- self.beamer_template_header_tex = self._try_read_list(options, "TEX", "Beamer_Header.tex", "full_beamer_header")
98
- self.beamer_template_tail_tex = self._try_read_list(options, "TEX", "Beamer_Tail.tex", "full_beamer_tail")
99
- self.math_commands_tex = self._try_read_list(options, "TEX", "math_commands.tex", "full_math_commands")
100
- self.usepackages_tex = self._try_read_list(options, "TEX", "Style.tex", "full_usepackages_tex")
67
+ """Initialize Python LaTeX processing configuration.
68
+
69
+ Args:
70
+ options (Dict[str, Any]): Configuration options.
71
+ """
72
+ self.article_template_header_tex = self._try_read_list("TEX", "Article_Header.tex")
73
+ self.article_template_tail_tex = self._try_read_list("TEX", "Article_Tail.tex")
74
+ self.beamer_template_header_tex = self._try_read_list("TEX", "Beamer_Header.tex")
75
+ self.beamer_template_tail_tex = self._try_read_list("TEX", "Beamer_Tail.tex")
76
+ self.math_commands_tex = self._try_read_list("TEX", "math_commands.tex")
77
+ self.usepackages_tex = self._try_read_list("TEX", "Style.tex")
101
78
 
102
79
  # handly preamble
103
80
  self.handly_preamble = options.get("handly_preamble", False)
@@ -106,12 +83,17 @@ class BasicInput(BasicInputInPyBibtexer):
106
83
  self.beamer_template_header_tex, self.beamer_template_tail_tex = [], []
107
84
  self.math_commands_tex, self.usepackages_tex = [], []
108
85
 
109
- def _try_read_list(self, options: Dict[str, Any], folder_name: str, file_name: str, key: str):
110
- path_file = os.path.join(self.path_templates, folder_name, file_name)
111
- if (p := options.get(key)) is None:
112
- return []
113
- else:
114
- path_file = p
86
+ def _try_read_list(self, folder_name: str, file_name: str):
87
+ """Try to read a list from a file in the templates directory.
88
+
89
+ Args:
90
+ folder_name (str): Name of the folder in templates directory.
91
+ file_name (str): Name of the file to read.
92
+
93
+ Returns:
94
+ List[str]: List of lines from the file, or empty list if file cannot be read.
95
+ """
96
+ path_file = os.path.join(self._path_templates, folder_name, file_name)
115
97
 
116
98
  try:
117
99
  data_list = read_list(path_file)
@@ -19,21 +19,26 @@ from .basic_input import BasicInput
19
19
 
20
20
 
21
21
  class PandocMdTo(BasicInput):
22
- """Pandoc md to md, tex, html, pdf and so on.
22
+ """Pandoc markdown to various formats (md, tex, html, pdf).
23
23
 
24
24
  Args:
25
- options (dict): Options.
25
+ options (dict): Configuration options.
26
26
 
27
27
  Attributes:
28
- markdown_name (str = "multi-markdown"): Markdown name.
29
- markdown_citation (str = "markdown_mmd"): Markdown citation.
30
- columns_in_md (int = 120): Columns in md.
31
- google_connected_paper_scite (bool = True): Google connected paper scite.
32
- display_one_line_reference_note (bool = False): Display one line reference note.
33
- cite_flag_in_tex (str = "cite"): Cite flag in tex.
28
+ markdown_name (str): Markdown name. Defaults to "multi-markdown".
29
+ markdown_citation (str): Markdown citation format. Defaults to "markdown_mmd".
30
+ columns_in_md (int): Number of columns in markdown. Defaults to 120.
31
+ google_connected_paper_scite (bool): Whether to use Google connected paper scite. Defaults to True.
32
+ display_one_line_reference_note (bool): Whether to display one line reference note. Defaults to False.
33
+ cite_flag_in_tex (str): Citation flag in LaTeX. Defaults to "cite".
34
34
  """
35
35
 
36
36
  def __init__(self, options: dict) -> None:
37
+ """Initialize PandocMdTo with configuration options.
38
+
39
+ Args:
40
+ options (dict): Configuration options.
41
+ """
37
42
  super().__init__(options)
38
43
 
39
44
  self.markdown_name: str = "multi-markdown"
@@ -47,21 +52,36 @@ class PandocMdTo(BasicInput):
47
52
  # tex
48
53
  self.cite_flag_in_tex: str = options.get("cite_flag_in_tex", "cite")
49
54
 
50
- # for pandoc markdown files to markdown files
51
55
  def pandoc_md_to_md(
52
- self,
53
- path_bib: str,
54
- path_md_one: str,
55
- path_md_two: str,
56
- name_md_one: Optional[str],
57
- name_md_two: Optional[str],
56
+ self, path_bib: str, path_md_one: str, path_md_two: str, name_md_one: Optional[str], name_md_two: Optional[str]
58
57
  ) -> List[str]:
58
+ """Convert markdown to markdown using pandoc.
59
+
60
+ Args:
61
+ path_bib (str): Path to bibliography file.
62
+ path_md_one (str): Path to source markdown directory.
63
+ path_md_two (str): Path to destination markdown directory.
64
+ name_md_one (Optional[str]): Name of source markdown file.
65
+ name_md_two (Optional[str]): Name of destination markdown file.
66
+
67
+ Returns:
68
+ List[str]: List of processed markdown content lines.
69
+ """
59
70
  full_one = path_md_one if name_md_one is None else os.path.join(path_md_one, name_md_one)
60
71
  full_two = path_md_two if name_md_two is None else os.path.join(path_md_two, name_md_two)
61
72
  return self._pandoc_md_to_md(full_one, full_two, path_bib)
62
73
 
63
74
  def _pandoc_md_to_md(self, full_md_one: str, full_md_two: str, path_bib: str) -> List[str]:
64
- """Pandoc."""
75
+ """Internal method to convert markdown to markdown using pandoc.
76
+
77
+ Args:
78
+ full_md_one (str): Full path to source markdown file.
79
+ full_md_two (str): Full path to destination markdown file.
80
+ path_bib (str): Path to bibliography file.
81
+
82
+ Returns:
83
+ List[str]: List of processed markdown content lines.
84
+ """
65
85
  if not os.path.exists(path_two := os.path.dirname(full_md_two)):
66
86
  os.makedirs(path_two)
67
87
 
@@ -79,7 +99,7 @@ class PandocMdTo(BasicInput):
79
99
  )
80
100
 
81
101
  try:
82
- subprocess.run(cmd, shell=True, check=True, capture_output=True, text=True)
102
+ subprocess.run(cmd.split(), check=True, capture_output=True, text=True)
83
103
  except subprocess.CalledProcessError as e:
84
104
  print("Pandoc error in pandoc md to md:", e.stderr)
85
105
 
@@ -99,12 +119,7 @@ class PandocMdTo(BasicInput):
99
119
 
100
120
  # for pandoc markdown files to tex files
101
121
  def pandoc_md_to_tex(
102
- self,
103
- template_name: str,
104
- path_md: str,
105
- path_tex: str,
106
- name_md: Optional[str],
107
- name_tex: Optional[str],
122
+ self, template_name: str, path_md: str, path_tex: str, name_md: Optional[str], name_tex: Optional[str]
108
123
  ) -> List[str]:
109
124
  full_one = path_md if name_md is None else os.path.join(path_md, name_md)
110
125
  full_two = path_tex if name_tex is None else os.path.join(path_tex, name_tex)
@@ -121,7 +136,7 @@ class PandocMdTo(BasicInput):
121
136
  cmd = f"pandoc {full_md} -o {full_tex} --from markdown "
122
137
 
123
138
  try:
124
- subprocess.run(cmd, shell=True, check=True, capture_output=True, text=True)
139
+ subprocess.run(cmd.split(), check=True, capture_output=True, text=True)
125
140
  except subprocess.CalledProcessError as e:
126
141
  print("Pandoc error in pandoc md to tex:", e.stderr)
127
142
 
@@ -155,7 +170,7 @@ class PandocMdTo(BasicInput):
155
170
  cmd = f"pandoc {full_md} -o {full_html} --from markdown "
156
171
 
157
172
  try:
158
- subprocess.run(cmd, shell=True, check=True, capture_output=True, text=True)
173
+ subprocess.run(cmd.split(), check=True, capture_output=True, text=True)
159
174
  except subprocess.CalledProcessError as e:
160
175
  print("Pandoc error in pandoc md to html:", e.stderr)
161
176
 
@@ -167,13 +182,7 @@ class PandocMdTo(BasicInput):
167
182
  return ""
168
183
 
169
184
  # for pandoc markdown files to pdf files
170
- def pandoc_md_to_pdf(
171
- self,
172
- path_md: str,
173
- path_pdf: str,
174
- name_md: Optional[str],
175
- name_pdf: Optional[str],
176
- ) -> str:
185
+ def pandoc_md_to_pdf(self, path_md: str, path_pdf: str, name_md: Optional[str], name_pdf: Optional[str]) -> str:
177
186
  full_one = path_md if name_md is None else os.path.join(path_md, name_md)
178
187
  full_two = path_pdf if name_pdf is None else os.path.join(path_pdf, name_pdf)
179
188
  return self._pandoc_md_to_pdf(full_one, full_two)
@@ -192,7 +201,7 @@ class PandocMdTo(BasicInput):
192
201
  cmd = f"pandoc {full_md} -o {full_pdf} --from markdown --listings --pdf-engine=xelatex"
193
202
 
194
203
  try:
195
- subprocess.run(cmd, shell=True, check=True, capture_output=True, text=True)
204
+ subprocess.run(cmd.split(), check=True, capture_output=True, text=True)
196
205
  except subprocess.CalledProcessError as e:
197
206
  print("Pandoc error in pandoc md to pdf:", e.stderr)
198
207
 
@@ -203,17 +212,13 @@ class PandocMdTo(BasicInput):
203
212
  # --------- --------- --------- --------- --------- --------- --------- --------- --------- #
204
213
  # md
205
214
  def generate_key_data_dict(
206
- self,
207
- pandoc_md_data_list: List[str],
208
- key_url_http_bib_dict: Dict[str, List[List[str]]],
215
+ self, pandoc_md_data_list: List[str], key_url_http_bib_dict: Dict[str, List[List[str]]]
209
216
  ) -> Tuple[Dict[str, List[str]], Dict[str, List[str]], Dict[str, List[str]]]:
210
217
  """Generate."""
211
218
  key_reference_dict = self._generate_citation_key_reference_dict_from_pandoc_md(pandoc_md_data_list)
212
- (
213
- key_basic_dict,
214
- key_beauty_dict,
215
- key_complex_dict,
216
- ) = self._generate_basic_beauty_complex_dict(key_url_http_bib_dict, key_reference_dict)
219
+ (key_basic_dict, key_beauty_dict, key_complex_dict) = self._generate_basic_beauty_complex_dict(
220
+ key_url_http_bib_dict, key_reference_dict
221
+ )
217
222
  return key_basic_dict, key_beauty_dict, key_complex_dict
218
223
 
219
224
  def _generate_citation_key_reference_dict_from_pandoc_md(
@@ -281,9 +286,7 @@ class PandocMdTo(BasicInput):
281
286
  return delete_empty_lines_last_occur_add_new_line(new_list)
282
287
 
283
288
  def _generate_basic_beauty_complex_dict(
284
- self,
285
- key_url_http_bib_dict: Dict[str, List[List[str]]],
286
- key_reference_dict: Dict[str, list],
289
+ self, key_url_http_bib_dict: Dict[str, List[List[str]]], key_reference_dict: Dict[str, list]
287
290
  ) -> Tuple[Dict[str, List[str]], Dict[str, List[str]], Dict[str, List[str]]]:
288
291
  """Generate."""
289
292
  header_list = ["<details>\n", "```\n"]
@@ -331,9 +334,7 @@ class PandocMdTo(BasicInput):
331
334
  insert_part_one, insert_part_two = self._generate_tex_content(file_prefix, add_tex_name, add_bib_name)
332
335
 
333
336
  # write tex
334
- data_temp = insert_list_in_list(
335
- self.article_template_tex, insert_part_one, r"\\begin{document}", "before"
336
- )
337
+ data_temp = insert_list_in_list(self.article_template_tex, insert_part_one, r"\\begin{document}", "before")
337
338
  data_temp = insert_list_in_list(data_temp, insert_part_two, r"\\begin{document}", "after")
338
339
  write_list(data_temp, f"{file_prefix}.tex", "w", os.path.join(path_combine, "tex"))
339
340
  return None
@@ -5,12 +5,7 @@ import shutil
5
5
  import time
6
6
  from typing import Any, Dict, List, Tuple
7
7
 
8
- from pyadvtools import (
9
- combine_content_in_list,
10
- delete_empty_lines_last_occur_add_new_line,
11
- read_list,
12
- write_list,
13
- )
8
+ from pyadvtools import combine_content_in_list, delete_empty_lines_last_occur_add_new_line, read_list, write_list
14
9
  from pybibtexer.bib.core import ConvertStrToLibrary
15
10
  from pybibtexer.main.python_writers import PythonWriters
16
11
 
@@ -19,21 +14,26 @@ from .pandoc_md_to import PandocMdTo
19
14
 
20
15
 
21
16
  class PythonRunMd(BasicInput):
22
- """Python markdown.
17
+ """Python markdown processing class.
23
18
 
24
19
  Args:
25
- options (Dict[str, Any]): Options.
20
+ options (Dict[str, Any]): Configuration options.
26
21
 
27
22
  Attributes:
28
- delete_temp_generate_md (bool = True): Whether to delete temp generate md.
29
- add_reference_in_md (bool = True): Whether to add reference in md.
30
- add_bib_in_md (bool = False): Whether to add bib in md.
31
- replace_cite_to_fullcite_in_md (bool = False): Whether to replace cite to fullcite in md.
32
- replace_by_basic_beauty_complex_in_md (str = "beauty"): Replace by basic, beauty, or complex.
33
- display_basic_beauty_complex_references_in_md (str = "beauty"): Display basic, beauty, or complex references.
23
+ delete_temp_generate_md (bool): Whether to delete temporary generated markdown files. Defaults to True.
24
+ add_reference_in_md (bool): Whether to add references in markdown. Defaults to True.
25
+ add_bib_in_md (bool): Whether to add bibliography in markdown. Defaults to False.
26
+ replace_cite_to_fullcite_in_md (bool): Whether to replace citations with full citations in markdown. Defaults to False.
27
+ replace_by_basic_beauty_complex_in_md (str): Replace by basic, beauty, or complex format. Defaults to "beauty".
28
+ display_basic_beauty_complex_references_in_md (str): Display basic, beauty, or complex references. Defaults to "beauty".
34
29
  """
35
30
 
36
31
  def __init__(self, options: Dict[str, Any]) -> None:
32
+ """Initialize PythonRunMd with configuration options.
33
+
34
+ Args:
35
+ options (Dict[str, Any]): Configuration options.
36
+ """
37
37
  super().__init__(options)
38
38
 
39
39
  # for md
@@ -56,7 +56,6 @@ class PythonRunMd(BasicInput):
56
56
  _options.update(options)
57
57
  self._generate_library = ConvertStrToLibrary(_options)
58
58
 
59
- # for markdown files
60
59
  def special_operate_for_md(
61
60
  self,
62
61
  path_output: str,
@@ -66,9 +65,23 @@ class PythonRunMd(BasicInput):
66
65
  full_bib_for_zotero: str,
67
66
  template_name: str = "article",
68
67
  generate_html: bool = False,
69
- generate_tex: bool = True
68
+ generate_tex: bool = True,
70
69
  ) -> Tuple[List[str], List[str]]:
71
- """Markdown."""
70
+ """Perform special operations on markdown files.
71
+
72
+ Args:
73
+ path_output (str): Path to output directory.
74
+ data_list_md (List[str]): List of markdown content lines.
75
+ output_md_name (str): Name of output markdown file.
76
+ full_bib_for_abbr (str): Path to abbreviated bibliography file.
77
+ full_bib_for_zotero (str): Path to Zotero bibliography file.
78
+ template_name (str, optional): Name of template to use. Defaults to "article".
79
+ generate_html (bool, optional): Whether to generate HTML. Defaults to False.
80
+ generate_tex (bool, optional): Whether to generate LaTeX. Defaults to True.
81
+
82
+ Returns:
83
+ Tuple[List[str], List[str]]: Tuple containing processed markdown and LaTeX content.
84
+ """
72
85
  path_temp = os.path.join(path_output, "{}".format(time.strftime("%Y_%m_%d_%H_%M_%S")))
73
86
  if not os.path.exists(path_temp):
74
87
  os.makedirs(path_temp)
@@ -118,12 +131,19 @@ class PythonRunMd(BasicInput):
118
131
  return data_list_md, data_list_tex
119
132
 
120
133
  def _special_operate_for_md(
121
- self,
122
- output_md_name: str,
123
- path_temp: str,
124
- full_bib_for_abbr: str,
125
- full_bib_for_zotero: str,
134
+ self, output_md_name: str, path_temp: str, full_bib_for_abbr: str, full_bib_for_zotero: str
126
135
  ) -> List[str]:
136
+ """Perform special operations for markdown processing.
137
+
138
+ Args:
139
+ output_md_name (str): Name of output markdown file.
140
+ path_temp (str): Path to temporary directory.
141
+ full_bib_for_abbr (str): Path to abbreviated bibliography file.
142
+ full_bib_for_zotero (str): Path to Zotero bibliography file.
143
+
144
+ Returns:
145
+ List[str]: List of processed markdown content lines.
146
+ """
127
147
  # pandoc markdown to markdown
128
148
  n1 = "1_pandoc" + ".md"
129
149
  data_list_md = self._pandoc_md_to.pandoc_md_to_md(full_bib_for_abbr, path_temp, path_temp, output_md_name, n1)
@@ -135,7 +155,7 @@ class PythonRunMd(BasicInput):
135
155
  _options = {}
136
156
  _options.update(self.options)
137
157
  _options["add_index_to_enties"] = False
138
- _python_writers = PythonWriters(self.full_json_c, self.full_json_j, _options)
158
+ _python_writers = PythonWriters(_options)
139
159
  key_url_http_bib_dict = _python_writers.output_key_url_http_bib_dict(library)
140
160
 
141
161
  content_md = []
@@ -214,7 +234,16 @@ class PythonRunMd(BasicInput):
214
234
 
215
235
  @staticmethod
216
236
  def _special_format(temp_list: List[str], space_one: str, space_two: str) -> List[str]:
217
- # special format for alignment
237
+ """Apply special formatting for alignment.
238
+
239
+ Args:
240
+ temp_list (List[str]): List of strings to format.
241
+ space_one (str): First space string.
242
+ space_two (str): Second space string.
243
+
244
+ Returns:
245
+ List[str]: Formatted list of strings.
246
+ """
218
247
  for j in range(len(temp_list) - 1):
219
248
  if temp_list[j][-1] == "\n":
220
249
  temp_list[j + 1] = (space_one + " " + space_two) + temp_list[j + 1]
@@ -228,6 +257,18 @@ class PythonRunMd(BasicInput):
228
257
  last_part: List[str],
229
258
  bib_in_md: List[str],
230
259
  ) -> List[str]:
260
+ """Generate markdown content from various components.
261
+
262
+ Args:
263
+ key_basic_beauty_complex_dict (Dict[str, List[str]]): Dictionary of formatted references.
264
+ key_in_md_tex (List[str]): List of citation keys in markdown/LaTeX.
265
+ main_part (List[str]): Main content part.
266
+ last_part (List[str]): Last content part.
267
+ bib_in_md (List[str]): Bibliography content for markdown.
268
+
269
+ Returns:
270
+ List[str]: Generated markdown content.
271
+ """
231
272
  temp_b = []
232
273
  if self.add_reference_in_md:
233
274
  temp_b = combine_content_in_list([key_basic_beauty_complex_dict[k] for k in key_in_md_tex], ["\n"])
@@ -1,31 +1,32 @@
1
1
  import os
2
2
  import re
3
+ import shutil
3
4
  import subprocess
4
5
  from typing import Any, Dict, List, Optional
5
6
 
6
- from pyadvtools import (
7
- delete_files,
8
- insert_list_in_list,
9
- read_list,
10
- write_list,
11
- )
7
+ from pyadvtools import delete_files, insert_list_in_list, read_list, write_list
12
8
 
13
9
  from .basic_input import BasicInput
14
10
 
15
11
 
16
12
  class PythonRunTex(BasicInput):
17
- """Python tex.
13
+ """Python LaTeX processing class.
18
14
 
19
15
  Args:
20
- options (Dict[str, Any]): Options.
16
+ options (Dict[str, Any]): Configuration options.
21
17
 
22
18
  Attributes:
23
- run_latex (bool = False): Whether to run latex.
24
- pdflatex_xelatex (str = "pdflatex"): pdflatex or xelatex.
25
- delete_run_latex_cache (bool = True): Whether to delete run latex cache.
19
+ run_latex (bool): Whether to run LaTeX compilation. Defaults to False.
20
+ pdflatex_xelatex (str): LaTeX engine to use ('pdflatex' or 'xelatex'). Defaults to "pdflatex".
21
+ delete_run_latex_cache (bool): Whether to delete LaTeX cache files. Defaults to True.
26
22
  """
27
23
 
28
24
  def __init__(self, options: Dict[str, Any]) -> None:
25
+ """Initialize PythonRunTex with configuration options.
26
+
27
+ Args:
28
+ options (Dict[str, Any]): Configuration options.
29
+ """
29
30
  super().__init__(options)
30
31
 
31
32
  # for tex
@@ -46,10 +47,27 @@ class PythonRunTex(BasicInput):
46
47
  bib_name: str = "abbr.bib",
47
48
  template_name: str = "article",
48
49
  ) -> List[str]:
50
+ """Generate standard LaTeX data list with proper formatting.
51
+
52
+ Args:
53
+ data_list_body (List[str]): List of body content strings.
54
+ output_tex_name (str): Name of output LaTeX file.
55
+ path_output (str): Path to output directory.
56
+ figure_folder_name (str, optional): Name of figures folder. Defaults to "figs".
57
+ tex_folder_name (str, optional): Name of LaTeX folder. Defaults to "tex".
58
+ bib_folder_name (str, optional): Name of bibliography folder. Defaults to "bib".
59
+ bib_name (str, optional): Name of bibliography file. Defaults to "abbr.bib".
60
+ template_name (str, optional): Name of template to use. Defaults to "article".
61
+
62
+ Returns:
63
+ List[str]: List of processed LaTeX content strings.
64
+ """
49
65
  # for figures
50
66
  for i in range(len(data_list_body)):
51
67
  if re.search(r"\\includegraphics", data_list_body[i]):
52
- data_list_body[i] = data_list_body[i].replace(f".{os.sep}Figures{os.sep}", f".{os.sep}{figure_folder_name}{os.sep}")
68
+ data_list_body[i] = data_list_body[i].replace(
69
+ f".{os.sep}Figures{os.sep}", f".{os.sep}{figure_folder_name}{os.sep}"
70
+ )
53
71
  data_list_body[i] = data_list_body[i].replace(f"Figures{os.sep}", f"{figure_folder_name}{os.sep}")
54
72
  write_list(data_list_body, output_tex_name, "w", os.path.join(path_output, tex_folder_name), False)
55
73
 
@@ -58,7 +76,6 @@ class PythonRunTex(BasicInput):
58
76
  )
59
77
  return data_list_body
60
78
 
61
- # for tex files
62
79
  def _special_operate_tex(
63
80
  self,
64
81
  data_list_body: List[str],
@@ -69,6 +86,17 @@ class PythonRunTex(BasicInput):
69
86
  bib_folder_name: str,
70
87
  bib_name: str,
71
88
  ) -> None:
89
+ """Perform special operations on LaTeX files.
90
+
91
+ Args:
92
+ data_list_body (List[str]): List of body content strings.
93
+ template_name (str): Name of template to use.
94
+ output_tex_name (str): Name of output LaTeX file.
95
+ path_output (str): Path to output directory.
96
+ tex_folder_name (str): Name of LaTeX folder.
97
+ bib_folder_name (str): Name of bibliography folder.
98
+ bib_name (str): Name of bibliography file.
99
+ """
72
100
  # read template data
73
101
  template_h, template_t = [], []
74
102
  if template_name.lower() == "paper":
@@ -133,19 +161,22 @@ class PythonRunTex(BasicInput):
133
161
 
134
162
  # run latex
135
163
  if self.run_latex:
136
- os.chdir(path_output)
137
- cmd = "latexmk -{} {}".format(self.pdflatex_xelatex, main_name)
138
- try:
139
- subprocess.run(cmd, shell=True, check=True, capture_output=True, text=True)
140
- except subprocess.CalledProcessError as e:
141
- print("Error in Run LaTex:", e.stderr)
164
+ if shutil.which("latexmk"):
165
+ os.chdir(path_output)
166
+ cmd = "latexmk -{} {}".format(self.pdflatex_xelatex, main_name)
167
+ try:
168
+ subprocess.run(cmd.split(), check=True, capture_output=True, text=True)
169
+ except subprocess.CalledProcessError as e:
170
+ print("Error in Run LaTex:", e.stderr)
171
+ else:
172
+ print("latexmk not found. Please install Texlive.")
142
173
 
143
174
  # delete cache
144
175
  if self.delete_run_latex_cache:
145
176
  if self.latex_clean_file_types is not None:
146
177
  postfix = self.latex_clean_file_types
147
178
  else:
148
- postfix = ['.aux', '.bbl', '.bcf', '.blg', '.fdb_latexmk', '.fls', '.log', '.out', '.run.xml']
149
- postfix.extend(['.synctex.gz', '.gz', '.nav', '.snm', '.toc', '.xdv'])
179
+ postfix = [".aux", ".bbl", ".bcf", ".blg", ".fdb_latexmk", ".fls", ".log", ".out", ".run.xml"]
180
+ postfix.extend([".synctex.gz", ".gz", ".nav", ".snm", ".toc", ".xdv"])
150
181
  delete_files(path_output, postfix)
151
182
  return None