tangle-md2tex 0.1.0__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.
@@ -0,0 +1,12 @@
1
+ Metadata-Version: 2.4
2
+ Name: tangle-md2tex
3
+ Version: 0.1.0
4
+ Summary: Extract LaTeX fenced blocks from literate Markdown files.
5
+ Author-email: yindaheng98 <yindaheng98@gmail.com>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/yindaheng98/tangle-md2tex
8
+ Project-URL: Repository, https://github.com/yindaheng98/tangle-md2tex
9
+ Requires-Python: >=3.10
10
+ License-File: LICENSE
11
+ Requires-Dist: markdown-it-py>=4.2.0
12
+ Dynamic: license-file
@@ -0,0 +1,11 @@
1
+ tangle_md2tex-0.1.0.dist-info/licenses/LICENSE,sha256=oI-e71S3HyCSR40MoS3enu_1Z6yayOKmcV_4b2fXqq4,1067
2
+ tanglemd2tex/__init__.py,sha256=ONkVrANA2LtjrXwNaiHbWdA1Jdgay6nPTj1Re9dJFh0,109
3
+ tanglemd2tex/__main__.py,sha256=PSQ4rpL0dG6f-qH4N7H-gD9igQkdHzH4yVZDcW8lfZo,80
4
+ tanglemd2tex/cli.py,sha256=Q6Oj2aDnUSXfwsy11gT5sOhFJEvMGWmERjNmg-toJks,1317
5
+ tanglemd2tex/lit_file.py,sha256=HhL3W1y3eezJoQAnhYqO5p06sa9yGDgyYneuszDRLiI,852
6
+ tanglemd2tex/tangle.py,sha256=0hUihGUTnEAkQVkpDxQOGE_JT92N-zUiHZJ7a9B80vw,582
7
+ tangle_md2tex-0.1.0.dist-info/METADATA,sha256=-cNucKOQudTnRy2-7QFtMdcy_mBxEZxrBHsvfVS9eFY,441
8
+ tangle_md2tex-0.1.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
9
+ tangle_md2tex-0.1.0.dist-info/entry_points.txt,sha256=owkLxIYwyAPkYuYUwh8u-7o634MoeMqcYth1i2VCteM,55
10
+ tangle_md2tex-0.1.0.dist-info/top_level.txt,sha256=1Y1In3h4AwH7NPGbY07R52TNAzE7gTilcdkQMqCB_AI,13
11
+ tangle_md2tex-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (82.0.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ tanglemd2tex = tanglemd2tex.cli:main
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Howard Yin
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ tanglemd2tex
@@ -0,0 +1,4 @@
1
+ from .tangle import tangle_text, tangle_file
2
+
3
+ __all__ = ["tangle_text", "tangle_file"]
4
+ __version__ = "0.1.0"
@@ -0,0 +1,5 @@
1
+ from .cli import main
2
+
3
+
4
+ if __name__ == "__main__":
5
+ raise SystemExit(main())
tanglemd2tex/cli.py ADDED
@@ -0,0 +1,55 @@
1
+ from __future__ import annotations
2
+
3
+ import argparse
4
+ import sys
5
+ from pathlib import Path
6
+
7
+ from .lit_file import find_lit_files
8
+ from .tangle import tangle_file
9
+
10
+
11
+ def build_parser() -> argparse.ArgumentParser:
12
+ parser = argparse.ArgumentParser(
13
+ prog="tanglemd2tex",
14
+ description="Extract ```latex``` fenced blocks from .lit.md files into .tex files.",
15
+ )
16
+ parser.add_argument(
17
+ "paths",
18
+ nargs="*",
19
+ type=Path,
20
+ help=(
21
+ ".lit.md files or directories to scan recursively. "
22
+ "Defaults to the current directory."
23
+ ),
24
+ )
25
+ return parser
26
+
27
+
28
+ def main(argv: list[str] | None = None) -> int:
29
+ parser = build_parser()
30
+ args = parser.parse_args(argv)
31
+
32
+ paths = args.paths or [Path(".")]
33
+
34
+ try:
35
+ lit_files = find_lit_files(paths)
36
+ except Exception as error:
37
+ print(f"ERROR: {error}", file=sys.stderr)
38
+ return 1
39
+
40
+ if not lit_files:
41
+ print("ERROR: no .lit.md files found", file=sys.stderr)
42
+ return 1
43
+
44
+ status = 0
45
+ for lit_path in lit_files:
46
+ try:
47
+ tex_path = tangle_file(lit_path)
48
+ except Exception as error:
49
+ print(f"ERROR: {error}", file=sys.stderr)
50
+ status = 1
51
+ continue
52
+
53
+ print(f"WROTE: {tex_path}")
54
+
55
+ return status
@@ -0,0 +1,34 @@
1
+ from __future__ import annotations
2
+
3
+ from pathlib import Path
4
+
5
+
6
+ LIT_SUFFIX = ".lit.md"
7
+ TEX_SUFFIX = ".tex"
8
+
9
+
10
+ def lit_to_tex_path(lit_path: Path) -> Path:
11
+ if not lit_path.name.endswith(LIT_SUFFIX):
12
+ raise ValueError(f"not a {LIT_SUFFIX} file: {lit_path}")
13
+
14
+ tex_name = lit_path.name[: -len(LIT_SUFFIX)] + TEX_SUFFIX
15
+ return lit_path.with_name(tex_name)
16
+
17
+
18
+ def find_lit_files(paths: list[Path]) -> list[Path]:
19
+ files: list[Path] = []
20
+
21
+ for path in paths:
22
+ if path.is_dir():
23
+ files.extend(path.rglob(f"*{LIT_SUFFIX}"))
24
+ continue
25
+
26
+ if path.is_file():
27
+ if not path.name.endswith(LIT_SUFFIX):
28
+ raise ValueError(f"not a {LIT_SUFFIX} file: {path}")
29
+ files.append(path)
30
+ continue
31
+
32
+ raise ValueError(f"path does not exist: {path}")
33
+
34
+ return files
tanglemd2tex/tangle.py ADDED
@@ -0,0 +1,22 @@
1
+ from __future__ import annotations
2
+
3
+ from pathlib import Path
4
+ from markdown_it import MarkdownIt
5
+
6
+ from .lit_file import lit_to_tex_path
7
+
8
+
9
+ def tangle_text(text: str) -> str:
10
+ return "".join(
11
+ token.content
12
+ for token in MarkdownIt("commonmark").parse(text)
13
+ if token.type == "fence" and token.info.strip() == "latex"
14
+ )
15
+
16
+
17
+ def tangle_file(lit_path: Path) -> Path:
18
+ tex_path = lit_to_tex_path(lit_path)
19
+ text = lit_path.read_text(encoding="utf-8")
20
+ tex_text = tangle_text(text)
21
+ tex_path.write_text(tex_text, encoding="utf-8")
22
+ return tex_path