Skip to content

Commit b0fe1cc

Browse files
authored
Merge pull request #35 from nschloe/more-input-files
More input files
2 parents 5f61441 + f2bb3ab commit b0fe1cc

File tree

4 files changed

+21
-28
lines changed

4 files changed

+21
-28
lines changed

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ comments from a given file and corrects [some common
1818
anti-patterns](http://mirrors.ctan.org/info/l2tabu/english/l2tabuen.pdf). For example,
1919
with
2020
```
21-
blacktex in.tex out.tex
21+
blacktex in.tex > out.tex
2222
```
2323
the input file
2424
```latex
@@ -37,9 +37,9 @@ and \(y = 2^n g\) with \(n = 1,\dots,10\), we have \(\frac{\Gamma}{2} = 8\).
3737
```
3838
You can use
3939
```
40-
blacktex -i in.tex
40+
blacktex -i in0.tex in1.tex ...
4141
```
42-
to modify a file in-place. See `blacktex -h` for all options.
42+
to modify files in-place. See `blacktex -h` for all options.
4343

4444
### Installation
4545

setup.cfg

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = blacktex
3-
version = 0.4.0
3+
version = 0.5.0
44
author = Nico Schlömer
55
author_email = [email protected]
66
description = Cleans up your LaTeX files

src/blacktex/cli.py

+15-19
Original file line numberDiff line numberDiff line change
@@ -8,36 +8,32 @@ def main(argv=None):
88
parser = _get_parser()
99
args = parser.parse_args(argv)
1010

11-
out = blacktex.clean(args.infile.read(), args.keep_comments, args.keep_dollar_math)
11+
stdout = []
12+
for fl in args.infiles:
13+
content = fl.read()
14+
out = blacktex.clean(content, args.keep_comments, args.keep_dollar_math)
15+
if args.in_place:
16+
with open(fl.name, "w") as f:
17+
f.write(out)
18+
else:
19+
stdout.append(out)
1220

13-
if args.in_place:
14-
with open(args.infile.name, "w") as f:
15-
f.write(out)
16-
else:
17-
args.outfile.write(out)
21+
if not args.in_place:
22+
return "\n".join(stdout)
1823

1924

2025
def _get_parser():
2126
parser = argparse.ArgumentParser(description="Clean up LaTeX files.")
2227

2328
parser.add_argument(
24-
"infile",
25-
nargs="?",
29+
"infiles",
30+
nargs="+",
2631
type=argparse.FileType("r"),
27-
default=sys.stdin,
28-
help="input LaTeX file (default: stdin)",
32+
help="input LaTeX file",
2933
)
3034

3135
parser.add_argument(
32-
"outfile",
33-
nargs="?",
34-
type=argparse.FileType("w"),
35-
default=sys.stdout,
36-
help="output LaTeX file (default: stdout)",
37-
)
38-
39-
parser.add_argument(
40-
"-i", "--in-place", action="store_true", help="modify infile in place"
36+
"-i", "--in-place", action="store_true", help="modify all files in place"
4137
)
4238

4339
parser.add_argument(

test/test_cli.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,9 @@ def test_cli():
88
with tempfile.TemporaryDirectory() as tmpdir:
99
tmpdir = Path(tmpdir)
1010
infile = tmpdir / "in.tex"
11-
outfile = tmpdir / "out.tex"
1211
with open(infile, "w") as f:
1312
f.write("a+b=c")
1413

15-
blacktex.cli.main([str(infile), str(outfile)])
14+
stdout = blacktex.cli.main([str(infile)])
1615

17-
with open(outfile) as f:
18-
line = f.read()
19-
assert line == "a+b = c"
16+
assert stdout == "a+b = c"

0 commit comments

Comments
 (0)