summaryrefslogtreecommitdiff
path: root/support/txt2latex
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
committerNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
commite0c6872cf40896c7be36b11dcc744620f10adf1d (patch)
tree60335e10d2f4354b0674ec22d7b53f0f8abee672 /support/txt2latex
Initial commit
Diffstat (limited to 'support/txt2latex')
-rw-r--r--support/txt2latex/txt2latex60
1 files changed, 60 insertions, 0 deletions
diff --git a/support/txt2latex/txt2latex b/support/txt2latex/txt2latex
new file mode 100644
index 0000000000..41a434a18b
--- /dev/null
+++ b/support/txt2latex/txt2latex
@@ -0,0 +1,60 @@
+#!/usr/bin/perl
+#
+# txt2latex -- by Tristan Miller (psychonaut@nothingisreal.com)
+# This program is in the public domain. It comes with absolutely NO
+# WARRANTY -- use at your own risk.
+#
+# Revision history
+# ----------------
+# 1.0 -- 2002/02/20 -- initial release
+#
+# Description
+# -----------
+# txt2latex assists in translation from ASCII text to LaTeX by escaping
+# special characters and "fixing" quote marks (using English conventions).
+# Reads from standard input and writes to standard output.
+# Any "unfixed" double quotes are reported on standard error.
+#
+# If there is a demand, I will add command-line options allowing
+# customization or suppression of the document header/footer, and use of
+# non-English quotation marks (e.g., "` and "').
+
+$count = 0;
+
+# Header
+print STDOUT "\\documentclass{article}\n\\begin{document}\n";
+
+foreach $line (<>) {
+
+ $count++;
+
+ # Escape special characters
+ $line =~ s/\\/{\\textbackslash}/g;
+ $line =~ s/{/\\{/g;
+ $line =~ s/}/\\}/g;
+ $line =~ s/\\{\\textbackslash\\}/{\\textbackslash}/g;
+ $line =~ s/\$/\\\$/g;
+ $line =~ s/%/\\%/g;
+ $line =~ s/_/\\_/g;
+ $line =~ s/&/\\&/g;
+ $line =~ s/\#/\\\#/g;
+
+ # Ellipses
+ $line =~ s/(^|[^.])\.\.\.([^.])/\1\\ldots\2/g;
+
+ # Fix double quotes
+ $line =~ s/(^|\s)\"/\1``/g;
+ $line =~ s/\"(\W|$)/''\1/g;
+
+ # Fix single quotes
+ $line =~ s/(^|\s)'/\1`/g;
+
+ if ($line =~ /\"/) {
+ print STDERR "txt2latex: unfixed quote mark on line $count\n";
+ }
+
+ print STDOUT $line;
+}
+
+# Footer
+print STDOUT "\\end{document}\n";