aboutsummaryrefslogtreecommitdiff
path: root/build/blog/2015-10-10-printing-long-80-character-per-line-plain-text-document-in-two-col...
diff options
context:
space:
mode:
authorneodarz <neodarz@neodarz.net>2017-04-28 00:30:19 +0200
committerneodarz <neodarz@neodarz.net>2017-04-28 00:30:19 +0200
commit9a88e9ff0385f66e7c565a394908503dc6e916ad (patch)
tree05ea8b356163f06c5fc99c2caf67fa8d3a28d67d /build/blog/2015-10-10-printing-long-80-character-per-line-plain-text-document-in-two-columns.html
parentf1965c50670f611ef54f9471490d45a554f7d866 (diff)
downloadmy_new_personal_website-9a88e9ff0385f66e7c565a394908503dc6e916ad.tar.xz
my_new_personal_website-9a88e9ff0385f66e7c565a394908503dc6e916ad.zip
Site updated at 2017-04-28T00:29:42+02:00
source branch was at: f1965c50670f611ef54f9471490d45a554f7d866 Correct a link
Diffstat (limited to 'build/blog/2015-10-10-printing-long-80-character-per-line-plain-text-document-in-two-columns.html')
-rw-r--r--build/blog/2015-10-10-printing-long-80-character-per-line-plain-text-document-in-two-columns.html56
1 files changed, 56 insertions, 0 deletions
diff --git a/build/blog/2015-10-10-printing-long-80-character-per-line-plain-text-document-in-two-columns.html b/build/blog/2015-10-10-printing-long-80-character-per-line-plain-text-document-in-two-columns.html
new file mode 100644
index 00000000..7e1752bd
--- /dev/null
+++ b/build/blog/2015-10-10-printing-long-80-character-per-line-plain-text-document-in-two-columns.html
@@ -0,0 +1,56 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8"/>
+<meta content="pandoc" name="generator"/>
+<meta content="Zhiming Wang" name="author"/>
+<meta content="2015-10-10T22:35:15-07:00" name="date"/>
+<title>Printing long, 80-character-per-line plain text document in two columns</title>
+<link href="/img/apple-touch-icon-152.png" rel="apple-touch-icon-precomposed"/>
+<meta content="#FFFFFF" name="msapplication-TileColor"/>
+<meta content="/img/favicon-144.png" name="msapplication-TileImage"/>
+<meta content="width=device-width, initial-scale=1" name="viewport"/>
+<link href="/css/normalize.min.css" media="all" rel="stylesheet" type="text/css"/>
+<link href="/css/theme.css" media="all" rel="stylesheet" type="text/css"/>
+<link href="/css/highlight.css" media="all" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<div id="archival-notice">This blog has been archived.<br/>Visit my home page at <a href="https://zhimingwang.org">zhimingwang.org</a>.</div>
+<nav class="nav">
+<a class="nav-icon" href="/" title="Home"><!--blog icon--></a>
+<a class="nav-title" href="/"><!--blog title--></a>
+<a class="nav-author" href="https://github.com/zmwangx" target="_blank"><!--blog author--></a>
+</nav>
+<article class="content">
+<header class="article-header">
+<h1 class="article-title">Printing long, 80-character-per-line plain text document in two columns</h1>
+<div class="article-metadata">
+<time class="article-timestamp" datetime="2015-10-10T22:35:15-07:00">October 10, 2015</time>
+</div>
+</header>
+<p><strong>TL; DR</strong>. Jump to <a href="#code">code</a>.</p>
+<hr/>
+<p>Printing is hard. Everyone who has ever tried to set up a printer (especially a multifunction unit) will probably agree with me. There are also a million ways to be sabotaged by your printer, e.g., connection failure (over Wi-Fi), toner running low, manual duplex eating two sheets at once when printing the second side. (Do you believe I encountered all three tonight?) Anyway, let's just assume that you have a perfectly connected, perfectly functional printer, and talk about something even harder.</p>
+<p>We nerds read 80-character-per-line (or 72, but it's safer to assume longer) plain text documents all the time, or at least occasionally if we exclude source code. A plain text document is extremely versatile; it looks awesome in a text editor or in a browser window — with monospace typeface of your choice and infinite scrolling or arbitrary pagination. However, the problem is, sometimes we want to put things into print for easier reference, and we do <em>not</em> have infinite scrolling or arbitrary pagination in print. We want to divide things up into pieces that fit nicely onto 8.5'' by 11'' sheets, without ruining the original formatting of the plain text document. Therefore, some program has to decide the page layout and translate the plain text document into something a printer understands, e.g., PostScript. But since plain text is so versatile, there are a million ways to lay it out on paper.</p>
+<p>You would assume that this is a solved problem, since the digital publishing industry has been around for 40 years; and you would assume that this should be easy on a Mac because it is a great platform for "creative professionals". And indeed it's not hard if you just want to print one column of 80 characters. You can even do that in TextEdit, where you pick a plain text font and font size so that lines don't wrap, and there you go. If you are using a more capable GUI text editor like TextWrangler (I use Emacs all the time but I don't know about printing from Emacs), you are given more customization options like header and line numbers. However, 80 character lines look awful on a 8.5'' wide page. Characters are HUGE (to me anyway). Note that monospaced fonts usually look better when they are smaller (I'm a <a href="/blog/2015-08-31-after-all-these-years-10pt-non-anti-aliased-monaco-is-still-the-best.html">10pt bitmap Monaco fan</a>), and do keep in mind that we are usually farther away from a computer screen than a piece of paper held in hand, so even "10pt" could look pretty big in print. Moreover, you most likely get the outlined version of your font in print rather than the bitmap version, which depending on your font of choice might not be a good thing, and the difference is amplified when characters are big. And above all, you waste a lot of paper this way, and create stapling problems for yourself when the document is long. In short, I don't find it a good solution.</p>
+<p>It would be much nicer if we could print in two columns. The characters will be pretty small so it's probably not very good for older people (or they could try two columns in landscape), but I'm still pretty young and have fairly good eyesight, so I like this idea. But turns out this is nontrivial with existing GUI programs, at least the ones that I know of. You could emulate the two-column layout by having four pages on one sheet, but it's really awkward because you get a page divider in each single column (waste of space), and page numbering would be all messed up. Other than that there's little you could do. I guess there's just not enough market for this particular need. Luckily we have a large selection of modular command line utilities that we can stitch together for great results. I'll cut the bullshit here and just show you the <span id="code">code</span> (for US letter):</p>
+<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="ex">curl</span> https://www.gnu.org/software/bash/manual/bash.txt \
+ <span class="kw">|</span> <span class="fu">pr</span> --columns=2 --width=168 --length=120 --form-feed --date-format=%Y-%m-%d --header=<span class="st">"Bash Reference Manual"</span> - \
+ <span class="kw">|</span> <span class="ex">enscript</span> --media=Letter --header= --font=Courier5.5 --margins=18:18:0:18 --output - \
+ <span class="kw">|</span> <span class="fu">ps2pdf</span> - bash-print.pdf</code></pre></div>
+<p>Here, as an example, I'm printing the ASCII text version of the Bash Reference Manual. <code>pr</code> ships with <code>coreutils</code> (OS X also ships with the BSD version of <code>pr</code>, but geez, I'm a <code>coreutils</code> fan), so if you just <code>brew install coreutils</code> then you should use <code>gpr</code> instead. <code>enscript</code> here is <a href="https://www.gnu.org/software/enscript/">GNU Enscript</a>, which could be installed with <code>brew install enscript</code> (credit to <a href="https://askubuntu.com/questions/27097/">Ask Ubuntu</a> for pointing me to this utility). <code>ps2pdf</code> ships with GhostScript, so you could do <code>brew install gs</code>, but you should already have it if you've got the MacTeX or TeXLive distribution installed. The options I'm using should be pretty self-explanatory and tweakable, but in case you don't understand something, just RTFM (that way you could also find more options). Anyway, a page of <code>bash-print.pdf</code> from the above looks like this (this one happen to be a 72-char-per-line document, whereas my numbers are tailored for 80; the image is at 300 ppi):</p>
+<div class="figure">
+<a href="/img/20151010-bash-print-sample-page.png" target="_blank"><img alt="Sample page from bash-print.pdf generated above. I drew a black, one-pixel border so you could tell the page from the background." src="/img/20151010-bash-print-sample-page.png"/></a>
+<p class="caption">Sample page from <code>bash-print.pdf</code> generated above. I drew a black, one-pixel border so you could tell the page from the background.</p>
+</div>
+<p>P.S. Preview.app on El Capitan just caught me by surprise. If memory serves, exporting PDF to PNG in Preview.app used to produce only one image for the current page, but now apparently you get a single, gigantic <a href="https://en.wikipedia.org/wiki/APNG">APNG</a> with each page in a frame. It's not very useful at 10 fps, though. Also, exporting to JPEG doesn't give you an MJPEG.</p>
+</article>
+<hr class="content-separator"/>
+<footer class="footer">
+<span class="rfooter">
+<a class="rss-icon" href="/rss.xml" target="_blank" title="RSS feed"><!--RSS feed icon--></a><a class="atom-icon" href="/atom.xml" target="_blank" title="Atom feed"><!--Atom feed icon--></a><a class="cc-icon" href="https://creativecommons.org/licenses/by/4.0/" target="_blank" title="Released under the Creative Commons Attribution 4.0 International license."><!--CC icon--></a>
+<a href="https://github.com/zmwangx" target="_blank">Zhiming Wang</a>
+</span>
+</footer>
+</body>
+</html>