txt2ebook 0.1.81__tar.gz → 0.1.83__tar.gz

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 (41) hide show
  1. {txt2ebook-0.1.81 → txt2ebook-0.1.83}/PKG-INFO +8 -5
  2. {txt2ebook-0.1.81 → txt2ebook-0.1.83}/README.md +5 -3
  3. {txt2ebook-0.1.81 → txt2ebook-0.1.83}/pyproject.toml +2 -1
  4. {txt2ebook-0.1.81 → txt2ebook-0.1.83}/src/txt2ebook/__init__.py +1 -1
  5. {txt2ebook-0.1.81 → txt2ebook-0.1.83}/src/txt2ebook/formats/__init__.py +3 -1
  6. txt2ebook-0.1.83/src/txt2ebook/formats/tex.py +95 -0
  7. {txt2ebook-0.1.81 → txt2ebook-0.1.83}/LICENSE.md +0 -0
  8. {txt2ebook-0.1.81 → txt2ebook-0.1.83}/src/txt2ebook/__main__.py +0 -0
  9. {txt2ebook-0.1.81 → txt2ebook-0.1.83}/src/txt2ebook/exceptions.py +0 -0
  10. {txt2ebook-0.1.81 → txt2ebook-0.1.83}/src/txt2ebook/formats/base.py +0 -0
  11. {txt2ebook-0.1.81 → txt2ebook-0.1.83}/src/txt2ebook/formats/epub.py +0 -0
  12. {txt2ebook-0.1.81 → txt2ebook-0.1.83}/src/txt2ebook/formats/gmi.py +0 -0
  13. {txt2ebook-0.1.81 → txt2ebook-0.1.83}/src/txt2ebook/formats/md.py +0 -0
  14. {txt2ebook-0.1.81 → txt2ebook-0.1.83}/src/txt2ebook/formats/pdf.py +0 -0
  15. {txt2ebook-0.1.81 → txt2ebook-0.1.83}/src/txt2ebook/formats/templates/__init__.py +0 -0
  16. {txt2ebook-0.1.81 → txt2ebook-0.1.83}/src/txt2ebook/formats/templates/epub/__init__.py +0 -0
  17. {txt2ebook-0.1.81 → txt2ebook-0.1.83}/src/txt2ebook/formats/templates/epub/clean.css +0 -0
  18. {txt2ebook-0.1.81 → txt2ebook-0.1.83}/src/txt2ebook/formats/templates/epub/condense.css +0 -0
  19. {txt2ebook-0.1.81 → txt2ebook-0.1.83}/src/txt2ebook/formats/templates/epub/noindent.css +0 -0
  20. {txt2ebook-0.1.81 → txt2ebook-0.1.83}/src/txt2ebook/formats/txt.py +0 -0
  21. {txt2ebook-0.1.81 → txt2ebook-0.1.83}/src/txt2ebook/formats/typ.py +0 -0
  22. {txt2ebook-0.1.81 → txt2ebook-0.1.83}/src/txt2ebook/helpers/__init__.py +0 -0
  23. {txt2ebook-0.1.81 → txt2ebook-0.1.83}/src/txt2ebook/languages/__init__.py +0 -0
  24. {txt2ebook-0.1.81 → txt2ebook-0.1.83}/src/txt2ebook/languages/en.py +0 -0
  25. {txt2ebook-0.1.81 → txt2ebook-0.1.83}/src/txt2ebook/languages/zh_cn.py +0 -0
  26. {txt2ebook-0.1.81 → txt2ebook-0.1.83}/src/txt2ebook/languages/zh_tw.py +0 -0
  27. {txt2ebook-0.1.81 → txt2ebook-0.1.83}/src/txt2ebook/locales/en/LC_MESSAGES/txt2ebook.mo +0 -0
  28. {txt2ebook-0.1.81 → txt2ebook-0.1.83}/src/txt2ebook/locales/en/LC_MESSAGES/txt2ebook.po +0 -0
  29. {txt2ebook-0.1.81 → txt2ebook-0.1.83}/src/txt2ebook/locales/txt2ebook.pot +0 -0
  30. {txt2ebook-0.1.81 → txt2ebook-0.1.83}/src/txt2ebook/locales/zh-cn/LC_MESSAGES/txt2ebook.mo +0 -0
  31. {txt2ebook-0.1.81 → txt2ebook-0.1.83}/src/txt2ebook/locales/zh-cn/LC_MESSAGES/txt2ebook.po +0 -0
  32. {txt2ebook-0.1.81 → txt2ebook-0.1.83}/src/txt2ebook/locales/zh-tw/LC_MESSAGES/txt2ebook.mo +0 -0
  33. {txt2ebook-0.1.81 → txt2ebook-0.1.83}/src/txt2ebook/locales/zh-tw/LC_MESSAGES/txt2ebook.po +0 -0
  34. {txt2ebook-0.1.81 → txt2ebook-0.1.83}/src/txt2ebook/models/__init__.py +0 -0
  35. {txt2ebook-0.1.81 → txt2ebook-0.1.83}/src/txt2ebook/models/book.py +0 -0
  36. {txt2ebook-0.1.81 → txt2ebook-0.1.83}/src/txt2ebook/models/chapter.py +0 -0
  37. {txt2ebook-0.1.81 → txt2ebook-0.1.83}/src/txt2ebook/models/volume.py +0 -0
  38. {txt2ebook-0.1.81 → txt2ebook-0.1.83}/src/txt2ebook/parser.py +0 -0
  39. {txt2ebook-0.1.81 → txt2ebook-0.1.83}/src/txt2ebook/tokenizer.py +0 -0
  40. {txt2ebook-0.1.81 → txt2ebook-0.1.83}/src/txt2ebook/txt2ebook.py +0 -0
  41. {txt2ebook-0.1.81 → txt2ebook-0.1.83}/src/txt2ebook/zh_utils.py +0 -0
@@ -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
@@ -31,14 +31,14 @@ txt2ebook --help
31
31
  ```
32
32
 
33
33
  ```console
34
- usage: txt2ebook [-of OUTPUT_FOLDER] [-p] [-f {epub,gmi,md,pdf,txt,typ}]
34
+ usage: txt2ebook [-of OUTPUT_FOLDER] [-p] [-f {epub,gmi,md,pdf,tex,txt,typ}]
35
35
  [-t TITLE] [-l LANGUAGE] [-a AUTHOR] [-tr TRANSLATOR]
36
36
  [-c IMAGE_FILENAME] [-w WIDTH] [-ff FILENAME_FORMAT]
37
37
  [-ps SEPARATOR] [-pz PAGE_SIZE] [-rd REGEX] [-rvc REGEX]
38
38
  [-rv REGEX] [-rc REGEX] [-rt REGEX] [-ra REGEX] [-rl REGEX]
39
39
  [-rr REGEX REGEX] [-et {clean,condense,noindent}] [-vp] [-tp]
40
40
  [-sp] [-ss] [-toc] [-hn] [-fw] [-rw] [-ow] [-op] [-q] [-v]
41
- [-y] [-d] [-h] [-V]
41
+ [-y] [-d] [--env] [-h] [-V]
42
42
  TXT_FILENAME [EBOOK_FILENAME]
43
43
 
44
44
  txt2ebook/tte is a cli tool to convert txt file to ebook format.
@@ -58,7 +58,7 @@ optional arguments:
58
58
  set default output folder (default: 'output')
59
59
  -p, --purge
60
60
  remove converted ebooks specified by --output-folder option (default: 'False')
61
- -f {epub,gmi,md,pdf,txt,typ}, --format {epub,gmi,md,pdf,txt,typ}
61
+ -f {epub,gmi,md,pdf,tex,txt,typ}, --format {epub,gmi,md,pdf,tex,txt,typ}
62
62
  ebook format (default: 'epub')
63
63
  -t TITLE, --title TITLE
64
64
  title of the ebook (default: 'None')
@@ -108,6 +108,8 @@ optional arguments:
108
108
  yes to prompt
109
109
  -d, --debug
110
110
  show debugging log and stacktrace
111
+ --env
112
+ print environments information for bug reporting
111
113
  -h, --help
112
114
  show this help message and exit
113
115
  -V, --version
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "txt2ebook"
3
- version = "0.1.81"
3
+ version = "0.1.83"
4
4
  description = "CLI tool to convert txt file to ebook format"
5
5
  authors = ["Kian-Meng Ang <kianmeng@cpan.org>"]
6
6
  license = "AGPL-3.0-or-later"
@@ -40,6 +40,7 @@ typing-extensions = "^4.5.0"
40
40
  reportlab = "^4.0.0"
41
41
  typst = "^0.10.0"
42
42
  importlib-resources = "^6.1.1"
43
+ pylatex = "^1.4.2"
43
44
 
44
45
  [tool.poetry.dev-dependencies]
45
46
  bandit = "^1.7.1"
@@ -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"
File without changes