Scale — “digits, yes please”

Just now and again one need a one-liner [0]. Just now and again it’s executed in bash [1]. Just now and again it involves some calculation. And just now and again it easy to do those things with bc [2] as it can read from standard input [3]. But at exactly those “now and again” times I normally find that bc truncates and returns only the integer part. Which at a subset of those “now and again” times are just not good enough. F.x.: one might be fuzzy about the resolution when counting how many keystrokes there are to go in order to have produced the scheduled amount of text for the day.

But fortunately I today got wiser; I met the scale variable in bc. It properly still truncates but now I can set a resolution that at least satisfy my fuzziness issue, which means I can now M-! my way to the following one-liner to get what i want.

C=`wc -c main.tex | cut -c 4-8`; P=`echo "scale=4; ${C}/2400" | bc`; echo ${C}c, ${P}p

Bliss. Back to work.

[0] http://en.wikipedia.org/wiki/One-liner_program
[1] http://www.gnu.org/software/bash/
[2] http://www.gnu.org/software/bc/
[3] http://en.wikipedia.org/wiki/Standard_input#Standard_input_.28stdin.29

6 Responses to “Scale — “digits, yes please””

  1. Anders K. Madsen Says:

    Hmm, trying to get number of standard pages? You might want to detex or untex it first.

    I use this:
    ‘echo “scale=1; `untex | wc -c`/2400″ | bc’
    That way I won’t have to worry as much about the amount of latex code in the document. (Try ‘untex
    ‘ to get the untexed version printed to stdout.)

  2. Steffen Says:

    You are right that it doesn’t strip the (La)TeX code, and hence return a number greater then what the un/de-tex method would and which might be more accurate. So in that sense my method is not accurate.

    BUT, it’s not very wrong. I’ve kept the LaTeX preamble in another file which is included with \input{} — there goes much of the TeXnicalities. What is left is a little bit for structuring using \begin{quote}, \section{} and \begin{itemize}. So it actually very little non-text that is counted.

    This, of cause, is only true in a certain kind of writing, namely those that don’t use a lot of LaTeX formatting. But that is at the same time the kind of writing were it at all makes sense to count “standard pages”.

    That said, it’s easier for me to count without un/detex as non of them are installed on my “terminal” from where i run Emacs. Nor is LaTeX for that matter.

  3. Anders K. Madsen Says:

    True, you do need to have untex/detex installed. :)
    If I do a ‘wc -c’ on the paper I’m currently working on, then I get 12833 chars, whereas ‘untex | wc -c’ gives me 10456 chars.
    That’s a difference of an entire std. page (but I use a LOT of itemize- and examples-environments, not to mention the \textipa{} every time I have to phonetically transcribe a word — and my preamble is in the actual file).

    But yeah, one should use whatever suits one (and one’s writing style) best. :)

  4. Steffen Says:

    New motto:

    “Have faith in the errors page counter as it brings you to the end target faster”

    I to put it differently; why should i trust the page counter in, say, MS Word.

  5. Anders K. Madsen Says:

    Haha! Well, one must simply assume that MS is capable of stripping out formatting and count the characters in their own formats. I would personally feel most comfortable about creating a PDF and then manually copy/paste the parts I want counted into a Unicode text document and then count the characters with a Unicode aware program. But it’s so much trouble and it takes so damn long. ;-p

    The problem is, if you’re too generous when counting chars, then you might get in trouble if the professor, who’s reading your paper, decides to check the number of chars in your specific paper. (I know, it barely ever happens, but you could fail an exam just because you slacked a little with the char.-counting.)

    Btw, I just noticed. WordPress converts tripple-dashes to an m-dash (or emdash) — just like LaTeX! Nice!

  6. Bjarke Sørensen Says:

    Maybe Word has it as a part of the wysiwyg.. So I guess it’s pretty accurate.

Leave a Reply

 Theme Brought to you by Directory Journal and Elegant Directory