txt2pdf 1.1.0 → 1.1.1

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 (3) hide show
  1. checksums.yaml +4 -4
  2. data/bin/txt2pdf +28 -6
  3. metadata +6 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cb854c44e3489ecbbe973adb9f66aa7896adc8c8f9a5be1291b26da0ec516735
4
- data.tar.gz: d4a72b1bfe65abc64c8f97c457e02351b61768a49c351d2d75b942da880510a4
3
+ metadata.gz: bbacc890a1d5e596f57dd38faf50fdd976e95c25680a505839f0b60fc090d060
4
+ data.tar.gz: 5e9a4df6e79b9bad42120e4db7c7b4b253572a746c6322f3bd5b9bcc9b8e9074
5
5
  SHA512:
6
- metadata.gz: dbad16297afc2aa14f4a71e904335f9550e062806c20efdbf316b21b6ec986bd49288660b42963856c27f3f9d36ae69af02788d5b1e79b8e71ac120514ce5123
7
- data.tar.gz: 6ee824e146ff8555aa186d012c9cb4547a329c17dbc2e534965e87a7e4438f0acc9bacebc5bceec93331123c3c014a29602ea8845a73fff0bec1ead06ebf8e42
6
+ metadata.gz: 6d6b9309bacc86e93105367042fe0c07f871f83bc8d003699b46c8c2d2fe9a2f2d57fe80e990101d7fcfa2c72a3e25a31f56818833bf36ffbb5d3aa30ecd5bc7
7
+ data.tar.gz: 4bacb76e9e02af1d20aa9e823184230291c02b640d7a321fb4f3ea28d4825cc65a7e5af3bc8f62e4d23029a8ce8b0fcc152a3ce5ee72dc52578bcc2432402f40
data/bin/txt2pdf CHANGED
@@ -61,8 +61,15 @@ if ARGV[0] == "-h"
61
61
  exit
62
62
  end
63
63
 
64
+ # Check that pdflatex is available
65
+ pdflatex_path = `which pdflatex 2>/dev/null`.strip
66
+ if pdflatex_path.empty?
67
+ $stderr.puts "Error: pdflatex not found. Install texlive or similar."
68
+ exit 1
69
+ end
70
+
64
71
  if ARGV[0]
65
- unless File.exists?(ARGV[0])
72
+ unless File.exist?(ARGV[0])
66
73
  puts "No such file"
67
74
  exit
68
75
  end
@@ -73,7 +80,18 @@ else
73
80
  fcont = ARGF.read
74
81
  end
75
82
 
76
- ftxt = fcont.gsub(/$/, '\\\\\\\\')
83
+ # Escape LaTeX special characters in user text
84
+ def escape_latex(text)
85
+ # Handle backslash first (before other replacements add backslashes)
86
+ text = text.gsub('\\', '\textbackslash{}')
87
+ # Escape the other special characters: { } $ & # ^ _ ~ %
88
+ text = text.gsub(/([{}\$&#\^_%~])/) { '\\' + $1 }
89
+ # Fix the braces that were part of \textbackslash{}
90
+ text = text.gsub('\\textbackslash\\{\\}', '\\textbackslash{}')
91
+ text
92
+ end
93
+
94
+ ftxt = escape_latex(fcont).gsub(/$/, '\\\\\\\\')
77
95
  txt = latexstart
78
96
  txt += "\\begin{document}\n\n"
79
97
  txt += ftxt
@@ -81,8 +99,12 @@ txt += "\n\\end{document}"
81
99
  ftex = fbase + ".tex"
82
100
  File.write(ftex, txt)
83
101
 
84
- `pdflatex #{ftex}`
85
- File.delete(ftex)
86
- File.delete(fbase + ".aux")
87
- File.delete(fbase + ".log")
102
+ temp_files = [ftex, fbase + ".aux", fbase + ".log"]
103
+ success = system("pdflatex -interaction=nonstopmode #{ftex} > /dev/null 2>&1")
104
+ temp_files.each { |f| File.delete(f) if File.exist?(f) }
105
+
106
+ unless success
107
+ $stderr.puts "Error: pdflatex failed to create PDF."
108
+ exit 1
109
+ end
88
110
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: txt2pdf
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Geir Isene
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-09-27 00:00:00.000000000 Z
11
+ date: 2026-03-21 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |-
14
14
  Reads a text file (if supplied as the first argument) and creates a pdf file with the same name but with .pdf as extension in the current directory via the program pdflatex (the only requirement besides ruby itself). If '-h' is the first argument, then the program displays the helptext and exits.
@@ -32,7 +32,7 @@ licenses:
32
32
  - Unlicense
33
33
  metadata:
34
34
  source_code_uri: https://github.com/isene/txt2pdf
35
- post_install_message:
35
+ post_install_message:
36
36
  rdoc_options: []
37
37
  require_paths:
38
38
  - lib
@@ -47,8 +47,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
47
47
  - !ruby/object:Gem::Version
48
48
  version: '0'
49
49
  requirements: []
50
- rubygems_version: 3.1.2
51
- signing_key:
50
+ rubygems_version: 3.4.20
51
+ signing_key:
52
52
  specification_version: 4
53
53
  summary: Converts plain text (file or from STDIN) to pdf via pdflatex
54
54
  test_files: []