txt2ebook 0.1.81__py3-none-any.whl → 0.1.83__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.81"
25
+ __version__ = "0.1.83"
26
26
 
27
27
 
28
28
  def setup_logger(config: argparse.Namespace) -> None:
@@ -24,12 +24,13 @@ from txt2ebook.formats.epub import EpubWriter
24
24
  from txt2ebook.formats.gmi import GmiWriter
25
25
  from txt2ebook.formats.md import MdWriter
26
26
  from txt2ebook.formats.pdf import PdfWriter
27
+ from txt2ebook.formats.tex import TexWriter
27
28
  from txt2ebook.formats.txt import TxtWriter
28
29
  from txt2ebook.formats.typ import TypWriter
29
30
  from txt2ebook.helpers import load_class, to_classname
30
31
  from txt2ebook.models import Book
31
32
 
32
- EBOOK_FORMATS = ["epub", "gmi", "md", "pdf", "txt", "typ"]
33
+ EBOOK_FORMATS = ["epub", "gmi", "md", "pdf", "tex", "txt", "typ"]
33
34
  PAGE_SIZES = [
34
35
  "a0",
35
36
  "a1",
@@ -82,6 +83,7 @@ __all__ = [
82
83
  "MdWriter",
83
84
  "PAGE_SIZES",
84
85
  "PdfWriter",
86
+ "TexWriter",
85
87
  "TxtWriter",
86
88
  "TypWriter",
87
89
  ]
@@ -0,0 +1,95 @@
1
+ # Copyright (C) 2021,2022,2023,2024 Kian-Meng Ang
2
+ #
3
+ # This program is free software: you can redistribute it and/or modify
4
+ # it under the terms of the GNU Affero General Public License as published by
5
+ # the Free Software Foundation, either version 3 of the License, or
6
+ # (at your option) any later version.
7
+ #
8
+ # This program is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ # GNU Affero General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU Affero General Public License
14
+ # along with this program. If not, see <https://www.gnu.org/licenses/>.
15
+
16
+ """Convert source text file into tex format."""
17
+
18
+ import importlib.resources as importlib_res
19
+ import logging
20
+ import sys
21
+ from pathlib import Path
22
+
23
+ import importlib_resources
24
+ from pylatex import Command as Cmd
25
+ from pylatex import Document as Doc
26
+ from pylatex import NoEscape as NoEsc
27
+ from pylatex import Package as Pkg
28
+ from pylatex.section import Chapter as Chap
29
+ from pylatex.section import Paragraph as Par
30
+ from pylatex.section import Part as Part
31
+
32
+ from txt2ebook.formats.base import BaseWriter
33
+ from txt2ebook.models import Chapter, Volume
34
+
35
+ # workaround for Python 3.8
36
+ # see https://github.com/messense/typst-py/issues/12#issuecomment-1812956252
37
+ setattr(importlib_res, "files", importlib_resources.files)
38
+ setattr(importlib_res, "as_file", importlib_resources.as_file)
39
+
40
+ logger = logging.getLogger(__name__)
41
+
42
+
43
+ class TexWriter(BaseWriter):
44
+ """Module for writing ebook in LaTeX (tex) format."""
45
+
46
+ def write(self) -> None:
47
+ """Generate Tex files."""
48
+ new_filename = self._output_filename(".tex")
49
+ new_filename.parent.mkdir(parents=True, exist_ok=True)
50
+
51
+ logger.info("Generate TeX file: %s", new_filename.resolve())
52
+
53
+ doc = Doc(documentclass="ctexbook", document_options=[self._fontset()])
54
+
55
+ doc.packages.append(Pkg("geometry", options=["a6paper"]))
56
+
57
+ hide_section_seq = (
58
+ r"chapter/name={},chapter/number={},part/name={},part/number={}"
59
+ )
60
+ doc.preamble.append(Cmd("ctexset", NoEsc(hide_section_seq)))
61
+ doc.preamble.append(Cmd("title", self.book.title))
62
+ doc.preamble.append(Cmd("author", ", ".join(self.book.authors)))
63
+ doc.preamble.append(Cmd("date", NoEsc(r"\today")))
64
+
65
+ doc.append(NoEsc(r"\maketitle"))
66
+ doc.append(NoEsc(r"\thispagestyle{empty}"))
67
+
68
+ for section in self.book.toc:
69
+ if isinstance(section, Volume):
70
+ with doc.create(Part(section.title)):
71
+ for chapter in section.chapters:
72
+ with doc.create(Chap(chapter.title)):
73
+ for paragraph in chapter.paragraphs:
74
+ doc.append(Par(paragraph.replace("\n", "")))
75
+ if isinstance(section, Chapter):
76
+ with doc.create(Chap(section.title)):
77
+ for paragraph in section.paragraphs:
78
+ doc.append(Par(paragraph.replace("\n", "")))
79
+
80
+ filename = str(new_filename.parent / new_filename.stem)
81
+ pdf_filename = Path(filename).with_suffix(".pdf")
82
+ doc.generate_pdf(filename, compiler="xelatex", clean_tex=False)
83
+
84
+ if self.config.open:
85
+ self._open_file(pdf_filename)
86
+
87
+ def _fontset(self) -> str:
88
+ if sys.platform == "linux":
89
+ return "fontset = ubuntu"
90
+
91
+ if sys.platform == "darwin":
92
+ return "fontset = macos"
93
+
94
+ if sys.platform == "windows":
95
+ return "fontset = windows"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: txt2ebook
3
- Version: 0.1.81
3
+ Version: 0.1.83
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
@@ -19,8 +19,8 @@ Classifier: Programming Language :: Python :: 3.8
19
19
  Classifier: Programming Language :: Python :: 3.9
20
20
  Classifier: Programming Language :: Python :: 3.10
21
21
  Classifier: Programming Language :: Python :: 3.11
22
- Classifier: Programming Language :: Python :: 3.12
23
22
  Classifier: Programming Language :: Python :: 3 :: Only
23
+ Classifier: Programming Language :: Python :: 3.12
24
24
  Classifier: Topic :: Text Processing
25
25
  Classifier: Topic :: Text Processing :: Filters
26
26
  Classifier: Topic :: Text Processing :: General
@@ -31,6 +31,7 @@ Requires-Dist: EbookLib (>=0.17.1,<0.18.0)
31
31
  Requires-Dist: bs4 (>=0.0.1,<0.0.2)
32
32
  Requires-Dist: importlib-resources (>=6.1.1,<7.0.0)
33
33
  Requires-Dist: langdetect (>=1.0.9,<2.0.0)
34
+ Requires-Dist: pylatex (>=1.4.2,<2.0.0)
34
35
  Requires-Dist: pypandoc (>=1.11,<2.0)
35
36
  Requires-Dist: regex (>=2021.11.10,<2022.0.0)
36
37
  Requires-Dist: reportlab (>=4.0.0,<5.0.0)
@@ -72,14 +73,14 @@ txt2ebook --help
72
73
  ```
73
74
 
74
75
  ```console
75
- usage: txt2ebook [-of OUTPUT_FOLDER] [-p] [-f {epub,gmi,md,pdf,txt,typ}]
76
+ usage: txt2ebook [-of OUTPUT_FOLDER] [-p] [-f {epub,gmi,md,pdf,tex,txt,typ}]
76
77
  [-t TITLE] [-l LANGUAGE] [-a AUTHOR] [-tr TRANSLATOR]
77
78
  [-c IMAGE_FILENAME] [-w WIDTH] [-ff FILENAME_FORMAT]
78
79
  [-ps SEPARATOR] [-pz PAGE_SIZE] [-rd REGEX] [-rvc REGEX]
79
80
  [-rv REGEX] [-rc REGEX] [-rt REGEX] [-ra REGEX] [-rl REGEX]
80
81
  [-rr REGEX REGEX] [-et {clean,condense,noindent}] [-vp] [-tp]
81
82
  [-sp] [-ss] [-toc] [-hn] [-fw] [-rw] [-ow] [-op] [-q] [-v]
82
- [-y] [-d] [-h] [-V]
83
+ [-y] [-d] [--env] [-h] [-V]
83
84
  TXT_FILENAME [EBOOK_FILENAME]
84
85
 
85
86
  txt2ebook/tte is a cli tool to convert txt file to ebook format.
@@ -99,7 +100,7 @@ optional arguments:
99
100
  set default output folder (default: 'output')
100
101
  -p, --purge
101
102
  remove converted ebooks specified by --output-folder option (default: 'False')
102
- -f {epub,gmi,md,pdf,txt,typ}, --format {epub,gmi,md,pdf,txt,typ}
103
+ -f {epub,gmi,md,pdf,tex,txt,typ}, --format {epub,gmi,md,pdf,tex,txt,typ}
103
104
  ebook format (default: 'epub')
104
105
  -t TITLE, --title TITLE
105
106
  title of the ebook (default: 'None')
@@ -149,6 +150,8 @@ optional arguments:
149
150
  yes to prompt
150
151
  -d, --debug
151
152
  show debugging log and stacktrace
153
+ --env
154
+ print environments information for bug reporting
152
155
  -h, --help
153
156
  show this help message and exit
154
157
  -V, --version
@@ -1,7 +1,7 @@
1
- txt2ebook/__init__.py,sha256=_TCqs7mbj-rTNP-FSDOlxwa265L2kRUEPgNb2K4FNLk,2061
1
+ txt2ebook/__init__.py,sha256=iD2uJuXzihfchfyYed9PS077YBUK268_w72rwNEgR4A,2061
2
2
  txt2ebook/__main__.py,sha256=gMLvgpqc_BL4cBqNe0vqErRF5dlJPAbvqu1zndcAHYI,850
3
3
  txt2ebook/exceptions.py,sha256=b2HDsXdqweLJbvSJEGt48nxvGkZq20SfYezSjwp77JU,842
4
- txt2ebook/formats/__init__.py,sha256=yjZsVk2L6FkUuEpyilp1XTrJeYYljws99vebiweWAKU,2395
4
+ txt2ebook/formats/__init__.py,sha256=WhiRWGvbUjc8QZfhAIkKCg6GL8vNNlEF73meZSzYhDA,2463
5
5
  txt2ebook/formats/base.py,sha256=5fICz70rbN9WKu0ZL1KwXsXEpDHYMry3qaFfNHilg1E,5840
6
6
  txt2ebook/formats/epub.py,sha256=ZRXRnEO-qCtRIQYM9zh-VaoJfrySRdAliWr5y91l_bA,6936
7
7
  txt2ebook/formats/gmi.py,sha256=deVCwFfCE7Ys9eFTnRgZUncJX6LiUM1iXG7HXFCHlPY,6783
@@ -12,6 +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=_Etvp6ZKNfcspd_dpYAaLZniJIH_YARbJEdsQO5zUfQ,3616
15
16
  txt2ebook/formats/txt.py,sha256=8PkJ54r-0saZYyYEH64nYSkM-oW5LnurCbAk6d2Ue78,7536
16
17
  txt2ebook/formats/typ.py,sha256=79WQyaexmNVJ0Xh7ykNjpwcS0vK7sdkSlrOBm-uV6dA,5200
17
18
  txt2ebook/helpers/__init__.py,sha256=cQmFjEsEEI0gRxDPL-284FMS5Z-iBMcu-4qe7Icf7is,1971
@@ -34,8 +35,8 @@ txt2ebook/parser.py,sha256=vdC--8I2c89xve7OA1OkYTDjSMwwKoyv4Wkmca0iFhE,11823
34
35
  txt2ebook/tokenizer.py,sha256=y1CQ3Xf5g74o_mUZSOwrwwu0grKmgmt6x3yxCWWokhU,9318
35
36
  txt2ebook/txt2ebook.py,sha256=Nwf30JA5aAXwHZEH1bnqXtD_eT3QBbpHQfsG4DP9uAc,13212
36
37
  txt2ebook/zh_utils.py,sha256=EgKVbwqYGaTGswQUGcOCeSfRelzwkAb9WWY9TrsX1x4,4882
37
- txt2ebook-0.1.81.dist-info/LICENSE.md,sha256=tGtFDwxWTjuR9syrJoSv1Hiffd2u8Tu8cYClfrXS_YU,31956
38
- txt2ebook-0.1.81.dist-info/METADATA,sha256=wOCWGoN2LiF9DMu554ChEraLRR55Fb7aCk_KJ0kCviQ,7388
39
- txt2ebook-0.1.81.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
40
- txt2ebook-0.1.81.dist-info/entry_points.txt,sha256=IQHyIIhd0MHjSSRVC1a6tMeIoLus8D06KHL_cumvEbg,83
41
- txt2ebook-0.1.81.dist-info/RECORD,,
38
+ txt2ebook-0.1.83.dist-info/LICENSE.md,sha256=tGtFDwxWTjuR9syrJoSv1Hiffd2u8Tu8cYClfrXS_YU,31956
39
+ txt2ebook-0.1.83.dist-info/METADATA,sha256=Dgflg8SSIEm9OZ-W1suCiAZ_us2tcvPcyBKMZTBplxk,7511
40
+ txt2ebook-0.1.83.dist-info/WHEEL,sha256=Zb28QaM1gQi8f4VCBhsUklF61CTlNYfs9YAZn-TOGFk,88
41
+ txt2ebook-0.1.83.dist-info/entry_points.txt,sha256=IQHyIIhd0MHjSSRVC1a6tMeIoLus8D06KHL_cumvEbg,83
42
+ txt2ebook-0.1.83.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: poetry-core 1.8.1
2
+ Generator: poetry-core 1.6.1
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any