m (Changes footnote to inline references)
m (Changes footnote to inline references)
Line 46: Line 46:
  
 
since usage wants that superscript quotation goes after the punctuation mark. If there is no punctuation, you'll want ''this\quote{ref7}'' to become ''this∼\quote{ref7}''. The following line of code does such a substitution: (the punctuation you want to be taken care of is in the square bracket [\.,;!?])
 
since usage wants that superscript quotation goes after the punctuation mark. If there is no punctuation, you'll want ''this\quote{ref7}'' to become ''this∼\quote{ref7}''. The following line of code does such a substitution: (the punctuation you want to be taken care of is in the square bracket [\.,;!?])
 +
(caution: replace the [[tilde]] below by a proper one)
  
 
<code lang='bash'>perl -p -e 's/([\.,;!?]*)(\\cite\{(\w+,)*\w+\})/∼\2\1/g;'  superscript.tex > inline.tex</code>
 
<code lang='bash'>perl -p -e 's/([\.,;!?]*)(\\cite\{(\w+,)*\w+\})/∼\2\1/g;'  superscript.tex > inline.tex</code>

Revision as of 17:00, 25 September 2012

{{{1}}}

Contents

Code

This page is still largely in progress.

This is a list of code we make available with no guarantee, beside the one that it did once work for its intended purpose.

Beware, version below one (e.g., v°0.1) are $\beta$-version. It might be that's all you find here.

  1. stampit — to stamp pdf files after their name.
  2. sanitize — to remove accents & special characters from filenames.
  3. putInDir — to move files inside directories bearing their name.
  4. uniqname — to generate a timestamp which can be used as a unique name.

Pattern substitutions

See Jukka “Yucca” Korpela's cheatsheet for regexps (archived)

Replace comma-separated digits by their point-separated counterpart

E.g, 123,45 → 123.45. To change in all .dat files:

perl -pi -w -e 's/(\d+),(\d+)/$1\.$2/g;' *dat

Sanitize CVS files

The following will sanitize all CSV files (here with extension .prf) from trailing text (headers, comments on lines following the CSV, etc.):

for f in *.prf; do cat "$f" | perl -ne 'print "$1\n" if /^([ \t]*([-+]?\d*\.?\d+([eE][-+]?\d+)?,)*[ \t]*[-+]?\d*\.?\d+([eE][-+]?\d+)?)/' > $f.dat ; done

This is a variation to keep all lines which have exactly 2 values (replace {1} by {$n-1$} to have exactly $n$ values per line):

for f in *.prf; do cat "$f" | perl -ne 'print "$1\n" if /^(([ \t]*[-+]?\d*\.?\d+([eE][-+]?\d+)?,){1}[ \t]*[-+]?\d*\.?\d+([eE][-+]?\d+)?)/' > $f.dat ; done

Be sure that you understand the script so that the sanitization goes to the depth you wish it to (for instance in its present form the first line of code will keep lines in the CSV file with a number but no comma as a valid line [with one value]).

Changes footnote to inline references

In a $\mathrm{\LaTeX}$ document, if you need to migrate from some superscript quoting like this,7 to some inline one like this~[7], you will likely need to replace

text like this,\quote{ref7}

to

text like this∼\quote{ref7},

since usage wants that superscript quotation goes after the punctuation mark. If there is no punctuation, you'll want this\quote{ref7} to become this∼\quote{ref7}. The following line of code does such a substitution: (the punctuation you want to be taken care of is in the square bracket [\.,;!?]) (caution: replace the tilde below by a proper one)

perl -p -e 's/([\.,;!?]*)(\\cite\{(\w+,)*\w+\})/∼\2\1/g;' superscript.tex > inline.tex

Note that APS has an option citeautoscript to take care of superscript quoting regardless of how you quote respectively to punctuation, but this is for the PRB style only.

\usepackage[aps,prb,citeautoscript]{revtex4-1}

Pretty print

We use Paul Grinberg's Code extension for Mediawiki to pretty-print source through GeSHi on our web.