txt2ebook 0.1.104__py3-none-any.whl → 0.1.107__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.
txt2ebook/__init__.py CHANGED
@@ -22,7 +22,7 @@ import sys
22
22
 
23
23
  logger = logging.getLogger(__name__)
24
24
 
25
- __version__ = "0.1.104"
25
+ __version__ = "0.1.107"
26
26
 
27
27
 
28
28
  def setup_logger(config: argparse.Namespace) -> None:
txt2ebook/formats/tex.py CHANGED
@@ -42,8 +42,13 @@ logger = logging.getLogger(__name__)
42
42
  class TexWriter(BaseWriter):
43
43
  """Module for writing ebook in LaTeX (tex) format."""
44
44
 
45
+ def __post_init__(self):
46
+ """Post init code."""
47
+ self.index_keywords = self.config.index_keyword + self.book.index
48
+ logger.debug("Index keywords: %s", self.index_keywords)
49
+
45
50
  def write(self) -> None:
46
- """Generate Tex files."""
51
+ """Generate TeX / PDF files."""
47
52
  new_filename = self._output_filename(".tex")
48
53
  new_filename.parent.mkdir(parents=True, exist_ok=True)
49
54
 
@@ -53,6 +58,7 @@ class TexWriter(BaseWriter):
53
58
 
54
59
  doc.packages.append(Pkg("geometry", options=["a6paper"]))
55
60
  doc.packages.append(Pkg("makeidx"))
61
+ doc.packages.append(Pkg("xcolor"))
56
62
  doc.packages.append(
57
63
  Pkg(
58
64
  "idxlayout",
@@ -122,21 +128,21 @@ class TexWriter(BaseWriter):
122
128
 
123
129
  filename = str(new_filename.parent / new_filename.stem)
124
130
  pdf_filename = Path(filename).with_suffix(".pdf")
125
- doc.generate_pdf(filename, compiler="latexmk", clean_tex=False)
131
+ doc.generate_pdf(
132
+ filename, compiler="latexmk", clean_tex=self.config.clean_tex
133
+ )
134
+ logger.info("Generate PDF file: %s", pdf_filename.resolve())
126
135
 
127
136
  if self.config.open:
128
137
  self._open_file(pdf_filename)
129
138
 
130
139
  def _process_paragraph(self, paragraph) -> str:
131
140
  par = paragraph.strip()
132
- for keyword in self.config.index_keyword:
133
- par = par.replace(
134
- keyword, rf"\index{{{keyword}}}\underline{{{keyword}}}"
135
- )
136
141
 
137
- for keyword in self.book.index:
142
+ for keyword in self.index_keywords:
138
143
  par = par.replace(
139
- keyword, rf"\index{{{keyword}}}\underline{{{keyword}}}"
144
+ keyword,
145
+ rf"\color{{red}}\index{{{keyword}}}{keyword}\color{{black}}",
140
146
  )
141
147
 
142
148
  return par
txt2ebook/txt2ebook.py CHANGED
@@ -109,6 +109,7 @@ def build_parser(
109
109
  epub = parser.add_argument_group("--format epub")
110
110
  pdf = parser.add_argument_group("--format pdf")
111
111
  txt = parser.add_argument_group("--format txt")
112
+ tex = parser.add_argument_group("--format tex")
112
113
  zhlang = parser.add_argument_group("--language zh-cn / --language zh-tw")
113
114
 
114
115
  if "--env" not in args:
@@ -343,6 +344,15 @@ def build_parser(
343
344
  metavar="REGEX",
344
345
  )
345
346
 
347
+ tex.add_argument(
348
+ "-ct",
349
+ "--clean-tex",
350
+ default=False,
351
+ action="store_true",
352
+ dest="clean_tex",
353
+ help="purge artifacts generated by TeX (default: '%(default)s')",
354
+ )
355
+
346
356
  epub.add_argument(
347
357
  "-et",
348
358
  "--epub-template",
@@ -526,6 +536,6 @@ def main(args: Optional[Sequence[str]] = None):
526
536
  except Exception as error:
527
537
  logger.error(
528
538
  getattr(error, "message", str(error)),
529
- exc_info=getattr(config, "debug", True),
539
+ exc_info=("-d" in args or "--debug" in args),
530
540
  )
531
541
  raise SystemExit(1) from None
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: txt2ebook
3
- Version: 0.1.104
3
+ Version: 0.1.107
4
4
  Summary: CLI tool to convert txt file to ebook format
5
5
  Home-page: https://github.com/kianmeng/txt2ebook
6
6
  License: AGPL-3.0-or-later
@@ -80,7 +80,7 @@ usage: txt2ebook [-of OUTPUT_FOLDER] [-p] [-f {epub,gmi,md,pdf,tex,txt,typ}]
80
80
  [-tr TRANSLATOR] [-c IMAGE_FILENAME] [-w WIDTH]
81
81
  [-ff FILENAME_FORMAT] [-ps SEPARATOR] [-pz PAGE_SIZE]
82
82
  [-rd REGEX] [-rvc REGEX] [-rv REGEX] [-rc REGEX] [-rt REGEX]
83
- [-ra REGEX] [-rl REGEX] [-rr REGEX REGEX]
83
+ [-ra REGEX] [-rl REGEX] [-rr REGEX REGEX] [-ct]
84
84
  [-et {clean,condense,noindent}] [-vp] [-tp] [-sp] [-ss]
85
85
  [-toc] [-hn] [-fw] [-rw] [-ow] [-op] [-q] [-v] [-y] [-d]
86
86
  [--env] [-h] [-V]
@@ -182,6 +182,10 @@ options:
182
182
  -toc, --table-of-content
183
183
  add table of content
184
184
 
185
+ --format tex:
186
+ -ct, --clean-tex
187
+ purge artifacts generated by TeX (default: 'False')
188
+
185
189
  --language zh-cn / --language zh-tw:
186
190
  -hn, --header-number
187
191
  convert section header from words to numbers
@@ -1,4 +1,4 @@
1
- txt2ebook/__init__.py,sha256=roBQocPyXl1Yj5SyBY3Rj_kqvP0XbafqmOuH2mxM5d4,2062
1
+ txt2ebook/__init__.py,sha256=xOZIcIZowSpX4k_0826-jTdVWL0al_0yiZiTJyvy7cE,2062
2
2
  txt2ebook/__main__.py,sha256=gMLvgpqc_BL4cBqNe0vqErRF5dlJPAbvqu1zndcAHYI,850
3
3
  txt2ebook/exceptions.py,sha256=b2HDsXdqweLJbvSJEGt48nxvGkZq20SfYezSjwp77JU,842
4
4
  txt2ebook/formats/__init__.py,sha256=WhiRWGvbUjc8QZfhAIkKCg6GL8vNNlEF73meZSzYhDA,2463
@@ -12,7 +12,7 @@ txt2ebook/formats/templates/epub/__init__.py,sha256=DeIsL4WDqgTU7zCLxlCidFItvG4N
12
12
  txt2ebook/formats/templates/epub/clean.css,sha256=AnEwMckzUSKcjKsDiWtJW1oaceuklt2tyuS1VbpVK1s,462
13
13
  txt2ebook/formats/templates/epub/condense.css,sha256=Fz80ZqkPsFRmGdURduAxqMV8drD0CCUlrv41P8rUsm8,477
14
14
  txt2ebook/formats/templates/epub/noindent.css,sha256=_O5Tv90TKyyPBRdgjuNKFwtKFbdheh2V9PtDhgRUg3U,483
15
- txt2ebook/formats/tex.py,sha256=s6ShjJ206fx524-MbrYkruC5kdBP3NU29KdDIcIEPkA,5670
15
+ txt2ebook/formats/tex.py,sha256=Z4nPTXcKFu2ZTsICuihDejmeNoQ9OSk7RT0VMJO2QGE,5892
16
16
  txt2ebook/formats/txt.py,sha256=8PkJ54r-0saZYyYEH64nYSkM-oW5LnurCbAk6d2Ue78,7536
17
17
  txt2ebook/formats/typ.py,sha256=MoARQTBMJFeOr4U0pf9JykC-FWos683hGhv-A8wh-uw,5232
18
18
  txt2ebook/helpers/__init__.py,sha256=cQmFjEsEEI0gRxDPL-284FMS5Z-iBMcu-4qe7Icf7is,1971
@@ -33,10 +33,10 @@ txt2ebook/models/chapter.py,sha256=buECAklNQgM3tDehzyVO9YfA_F0iXyLq2PaMZGV_Zaw,1
33
33
  txt2ebook/models/volume.py,sha256=HyT4XO9yZ8d0PgZVfMMyAYUDFv58RrUmsSFNNmU-sHY,1592
34
34
  txt2ebook/parser.py,sha256=DbivznOgBOzlY5btTdB09D6yNGk5QXsE-gD2zc6lJyc,12188
35
35
  txt2ebook/tokenizer.py,sha256=Bm56thLiYSmRDuFiAaOH-NibzhYZQvnLo_u21KaV4Oo,9406
36
- txt2ebook/txt2ebook.py,sha256=abYTP_62aqHhfetXW8oOIypUaQCLFI7nmZwHdcm7P24,13693
36
+ txt2ebook/txt2ebook.py,sha256=GwWjSk2HbnGrOM59qFsPv2CMqAgv1GBxy_r1zkgBEvQ,13969
37
37
  txt2ebook/zh_utils.py,sha256=EgKVbwqYGaTGswQUGcOCeSfRelzwkAb9WWY9TrsX1x4,4882
38
- txt2ebook-0.1.104.dist-info/LICENSE.md,sha256=tGtFDwxWTjuR9syrJoSv1Hiffd2u8Tu8cYClfrXS_YU,31956
39
- txt2ebook-0.1.104.dist-info/METADATA,sha256=flC602mGugcPuGRicCCk2TOJU7MTcbtXdDXoMX3MYJs,7656
40
- txt2ebook-0.1.104.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
41
- txt2ebook-0.1.104.dist-info/entry_points.txt,sha256=IQHyIIhd0MHjSSRVC1a6tMeIoLus8D06KHL_cumvEbg,83
42
- txt2ebook-0.1.104.dist-info/RECORD,,
38
+ txt2ebook-0.1.107.dist-info/LICENSE.md,sha256=tGtFDwxWTjuR9syrJoSv1Hiffd2u8Tu8cYClfrXS_YU,31956
39
+ txt2ebook-0.1.107.dist-info/METADATA,sha256=sKAw9NJB-ube8IQTCDZEePiaIdq3U_CTR7r5HR3EvSU,7754
40
+ txt2ebook-0.1.107.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
41
+ txt2ebook-0.1.107.dist-info/entry_points.txt,sha256=IQHyIIhd0MHjSSRVC1a6tMeIoLus8D06KHL_cumvEbg,83
42
+ txt2ebook-0.1.107.dist-info/RECORD,,