txt2pdf 1.1.0

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 +7 -0
  2. data/bin/txt2pdf +88 -0
  3. metadata +54 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: cb854c44e3489ecbbe973adb9f66aa7896adc8c8f9a5be1291b26da0ec516735
4
+ data.tar.gz: d4a72b1bfe65abc64c8f97c457e02351b61768a49c351d2d75b942da880510a4
5
+ SHA512:
6
+ metadata.gz: dbad16297afc2aa14f4a71e904335f9550e062806c20efdbf316b21b6ec986bd49288660b42963856c27f3f9d36ae69af02788d5b1e79b8e71ac120514ce5123
7
+ data.tar.gz: 6ee824e146ff8555aa186d012c9cb4547a329c17dbc2e534965e87a7e4438f0acc9bacebc5bceec93331123c3c014a29602ea8845a73fff0bec1ead06ebf8e42
data/bin/txt2pdf ADDED
@@ -0,0 +1,88 @@
1
+ #!/usr/bin/env ruby
2
+ # Converts plain text (file or from STDIN) to pdf via pdflatex
3
+ # ...either from a text file (first argument) or from STDIN
4
+ # By Geir Isene (https://isene.org/). No rights reserved.
5
+
6
+ def help # defines the helptext to be printed when option "-h" is used
7
+ puts <<HELPTEXT
8
+
9
+ NAME
10
+ txt2pdf
11
+
12
+ SYNOPSIS
13
+ txt2pdf [-h] (filename)
14
+
15
+ DESCRIPTION
16
+ Reads a text file (if supplied as the first argument) and creates
17
+ a pdf file with the same name but with .pdf as extension in the
18
+ current directory via the program pdflatex (the only requirement
19
+ besides ruby itself). If "-h" is the first argument, then the program
20
+ displays the helptext and exits.
21
+
22
+ The program can also read the input text from STDIN (STanDard IN) and
23
+ create the pdf file in the user's home directory. When this method is
24
+ used, no argument is given to the program and the text is simply piped
25
+ directly into the program like this:
26
+
27
+ $ echo "Hello" | txt2pdf
28
+
29
+ This would create a pdf file with only "Hello" and the page number
30
+ at the bottom of the resulting pdf page.
31
+
32
+ With this, you could map a key binding in your window manager to
33
+ create a pdf file from the text you selected in any program, be it the
34
+ terminal, your browser or your text editor. In my wm of choice, i3,
35
+ I have added the following to my i3 config:
36
+
37
+ bindsym $mod+p exec xclip -o | txt2pdf
38
+
39
+ This would create a pdf file from the text I have selected as I hit
40
+ the "Window button" and "p".
41
+
42
+ OPTIONS
43
+ -h Show this help text
44
+
45
+ COPYRIGHT:
46
+ By Geir Isene (https://isene.org) 2019. No rights reserved.
47
+
48
+ HELPTEXT
49
+ end
50
+
51
+ latexstart = <<LATEX #Edit this if you want to change your resulting pdf
52
+ \\documentclass[a4paper,10pt]{article}
53
+ \\addtolength{\\oddsidemargin}{-1in}
54
+ \\addtolength{\\evensidemargin}{-1in}
55
+ \\addtolength{\\textwidth}{2in}
56
+ \\setlength{\\parindent}{0pt}
57
+ LATEX
58
+
59
+ if ARGV[0] == "-h"
60
+ help
61
+ exit
62
+ end
63
+
64
+ if ARGV[0]
65
+ unless File.exists?(ARGV[0])
66
+ puts "No such file"
67
+ exit
68
+ end
69
+ fbase = File.basename(ARGV[0], ".*")
70
+ fcont = File::read(ARGV[0])
71
+ else
72
+ fbase = "selected"
73
+ fcont = ARGF.read
74
+ end
75
+
76
+ ftxt = fcont.gsub(/$/, '\\\\\\\\')
77
+ txt = latexstart
78
+ txt += "\\begin{document}\n\n"
79
+ txt += ftxt
80
+ txt += "\n\\end{document}"
81
+ ftex = fbase + ".tex"
82
+ File.write(ftex, txt)
83
+
84
+ `pdflatex #{ftex}`
85
+ File.delete(ftex)
86
+ File.delete(fbase + ".aux")
87
+ File.delete(fbase + ".log")
88
+
metadata ADDED
@@ -0,0 +1,54 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: txt2pdf
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Geir Isene
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-09-27 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: |-
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.
15
+
16
+ The program can also read the input text from STDIN (STanDard IN) and create the pdf file in the user's home directory. When this method is used, no argument is given to the program and the text is simply piped directly into the program like this: $ echo 'Hello' | txt2pdf
17
+
18
+ This would create a pdf file with only 'Hello' and the page number at the bottom of the resulting pdf page.
19
+
20
+ With this, you could map a key binding in your window manager to create a pdf file from the text you selected in any program, be it the terminal, your browser or your text editor. In my wm of choice, i3, I have added the following to my i3 config: bindsym $mod+p exec xclip -o | txt2pdf
21
+
22
+ This would create a pdf file from the text I have selected as I hit the 'Window Button' and 'p'.
23
+ email: g@isene.com
24
+ executables:
25
+ - txt2pdf
26
+ extensions: []
27
+ extra_rdoc_files: []
28
+ files:
29
+ - bin/txt2pdf
30
+ homepage: https://isene.com/
31
+ licenses:
32
+ - Unlicense
33
+ metadata:
34
+ source_code_uri: https://github.com/isene/txt2pdf
35
+ post_install_message:
36
+ rdoc_options: []
37
+ require_paths:
38
+ - lib
39
+ required_ruby_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ required_rubygems_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ requirements: []
50
+ rubygems_version: 3.1.2
51
+ signing_key:
52
+ specification_version: 4
53
+ summary: Converts plain text (file or from STDIN) to pdf via pdflatex
54
+ test_files: []