StrapDown.js script to produce a PDF document (and its documentation).
This commit is contained in:
263
strapdown2pdf
Executable file
263
strapdown2pdf
Executable file
@@ -0,0 +1,263 @@
|
||||
#!/usr/bin/env bash
|
||||
# By: Lilian BESSON
|
||||
# Email: Lilian.BESSON[AT]ens-cachan[DOT]fr
|
||||
# Date: 23-11-2014
|
||||
# Web: http://besson.qc.to/bin/strapdown2pdf
|
||||
# Web2: http://lbesson.bitbucket.org/strapdown2pdf.html
|
||||
#
|
||||
# strapdown2pdf, a small script to simply convert a "StrapDown.js flavored"
|
||||
# HTML file (used to write with a Markdown syntax) to a PDF document.
|
||||
#
|
||||
# More details on http://lbesson.bitbucket.org/strapdown2pdf.html
|
||||
#
|
||||
# Requirements:
|
||||
# + [lunamark](http://jgm.github.io/lunamark/lunamark.1.html)
|
||||
# + [autotex](http://besson.qc.to/bin/autotex) (from my webpage),
|
||||
# + [PDFCompress](http://besson.qc.to/bin/PDFCompress) (from my webpage),
|
||||
# + [pdflatex](http://besson.qc.to/bin/pdflatex) (from my webpage).
|
||||
#
|
||||
# References and more details:
|
||||
# + [StrapDown.js](http://lbesson.bitbucket.org/md/)
|
||||
#
|
||||
# Licence: [GPLv3](http://besson.qc.to/LICENCE.html)
|
||||
#
|
||||
# Bugs / FIXME:
|
||||
# 1. I think it is way better now. Hack something to preserve LaTeX code verbatim between $ $ in the HTML initial document
|
||||
# Example: http://javis/a/maths.html -> http://javis/a/maths.pdf works very well,
|
||||
# only for MathJax flavored maths formulas, which are all copied in the .tex with escaped $ and { : \{ and \$ every where :(
|
||||
#
|
||||
#
|
||||
version='0.8'
|
||||
AUTOTEX="autotex batchmode"
|
||||
|
||||
quiet="false"
|
||||
sign="false"
|
||||
keep="false"
|
||||
discrete="false"
|
||||
htm="false"
|
||||
|
||||
scale="0.85"
|
||||
policesize="11"
|
||||
|
||||
# $OPTARG can contain the argument of the option k (if specified with hvk: or hk:v for example)
|
||||
# while getopts vhqkmdsi option; do
|
||||
# FIXME: options with a for loop are better handled that getopts ? .. OK
|
||||
# case $option in
|
||||
for arg in "$@"; do
|
||||
case "$arg" in
|
||||
-v|-version|--version)
|
||||
echo -e "strapdown2pdf $version"
|
||||
exit 0
|
||||
;;
|
||||
-h|-help|--help)
|
||||
echo -e "${green}strapdown2pdf${white} -help | [options]"
|
||||
echo -e ""
|
||||
echo -e "Print a StrapDown-powered web-page to a PDF document, using lunamark and autotex."
|
||||
echo -e ""
|
||||
echo -e "Help:"
|
||||
echo -e " ${yellow}-h${white} to print this help message (and quit)."
|
||||
echo -e " ${yellow}-v${white} to print just the version of strapdown2pdf (and quit)."
|
||||
echo -e ""
|
||||
echo -e "Options:"
|
||||
echo -e " ${yellow}-i|-interactive${white} run PDFLaTeX with the interactive (errorstopmode) mode (default is batchmode)."
|
||||
echo -e " ${yellow}-q|-quiet${white} run strapdown2pdf in quiet mode (no output at all, everything is redirected to ${magenta}/tmp/strapdown2pdf.log${white})."
|
||||
echo -e " ${yellow}-m|-htm${white} run strapdown2pdf to produce a simple HTML file (which do not use StrapDown.js), written to a .htm file.\n\t\t\t For important document, producing a .htm autonomous file is a good idea."
|
||||
echo -e " ${yellow}-d|-discrete${white} run strapdown2pdf is discrete mode, without adding any creditentials in the produced document."
|
||||
echo -e " ${yellow}-s[0-9][0-9]*%${white} change the default scale used by autotex (default is 85%, '-70%', '-75%' or '-80%' are good also) ${cyan}"'New!'
|
||||
echo -e " ${yellow}-[0-9][0-9]*pt${white} change the default police size used by autotex (default is 11pt, '-10pt' or '-12pt' are good also) ${cyan}"'New!'
|
||||
echo -e " ${yellow}-k|-keep${white} keep the intermediate .tex file. ${cyan}"'New!'
|
||||
echo -e " ${yellow}-s|-sign${white} sign the produce PDF document with GnuPG (thanks to PDFCompress)."
|
||||
echo -e ""
|
||||
echo -e "strapdown2pdf v$version : Copyrights: (c) Lilian Besson 2011-2014."
|
||||
echo -e "Released under the term of the GPL v3 Licence (more details on http://besson.qc.to/LICENSE.html)."
|
||||
echo -e "In particular, strapdown2pdf is provided WITHOUT ANY WARANTY."
|
||||
exit 0
|
||||
;;
|
||||
-q|-quiet|--quiet)
|
||||
echo -e "${magenta}Running strapdown2pdf with option --quiet, to run silently.${white}"
|
||||
quiet="true"
|
||||
shift
|
||||
;;
|
||||
-k|-keep|--keep)
|
||||
echo -e "${magenta}Running strapdown2pdf with option --keep, to keep the intermediate .tex file.${white}"
|
||||
keep="true"
|
||||
shift
|
||||
;;
|
||||
-m|-htm|--htm)
|
||||
echo -e "${magenta}Running strapdown2pdf with option --htm, to produce a simple HTML file (which do not use StrapDown.js), written to a .htm file.${white}"
|
||||
htm="true"
|
||||
shift
|
||||
;;
|
||||
-d|-discrete|--discrete)
|
||||
echo -e "${magenta}Using raw document without adding any ${u}strapdown2pdf${U} and ${u}StrapDown${U}.js creditentials.${white}"
|
||||
discrete="true"
|
||||
shift
|
||||
;;
|
||||
-s|-sign|--sign)
|
||||
echo -e "${magenta}Running strapdown2pdf with option --sign, to sign the produced PDF (useless..).${white}"
|
||||
sign="true"
|
||||
shift
|
||||
;;
|
||||
-s[0-9][0-9]*%)
|
||||
scale="${arg//-s/}"
|
||||
scale=0."${scale//%/}"
|
||||
echo -e "${magenta}Running strapdown2pdf with option -s[0-9]*%, to choose the scale, which is now ${scale}.${white}"
|
||||
shift
|
||||
;;
|
||||
-[0-9][0-9]*pt)
|
||||
policesize="${arg//-/}"
|
||||
policesize="${policesize//pt/}"
|
||||
echo -e "${magenta}Running strapdown2pdf with option -[0-9][0-9]*pt, to choose the police size, which is now ${policesize}.${white}"
|
||||
shift
|
||||
;;
|
||||
-i|-interactive|--interactive)
|
||||
echo -e "${magenta}Using PDFLaTeX with '-interaction=errorstopmode' option (the compilation will pause if a problem occur).${white}"
|
||||
AUTOTEX="autotex errorstopmode"
|
||||
shift
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
StrapDown2PDF() {
|
||||
input="$(basename "$1")"
|
||||
name="${input%.html}"
|
||||
|
||||
# Be sure we have a nice HTML or Markdown file and not something else :)
|
||||
if [ "${name}.html" != "${input}" ]; then
|
||||
echo -e "${red}WARNING${white} The input file ${input} seems to not be a valid HTML file."
|
||||
if [ "${input%.md}.md" != "${input}" ]; then
|
||||
echo -e "${red}WARNING${white} The input file ${input} seems to not be a Markdown either."
|
||||
echo -e "${red}I prefer to quit NOW.${white}"
|
||||
exit 5
|
||||
else
|
||||
echo -e "${green}COOL${white} The input file ${input} seems to be a valid MarkDown file : ${blue}good :)${white}."
|
||||
name="${input%.md}"
|
||||
fi
|
||||
else
|
||||
echo -e "${green}COOL${white} The input file ${input} seems to be a valid MarkDown file or StrapDown-powered HTML file : ${blue}good :)${white}."
|
||||
fi
|
||||
# To be even more paranoid, I could search the HTML file and be sure that StrapDown.js is indeed used, but pfiou I'm lazy.
|
||||
|
||||
p="$(pwd)"
|
||||
|
||||
echo -e "Working with $u$input$U on $blue$p${white}." | tee -a /tmp/strapdown2pdf.log
|
||||
|
||||
echo -e "${magenta}The following lines will be removed :${white}"
|
||||
grep -n "^<" "$input"
|
||||
|
||||
# Remove HTML only lines (typically, the first one and the 4 last ones),
|
||||
grep -v "^<" "$input" \
|
||||
| sed s/'\\\\'/'\\\\\\\\'/g \
|
||||
| sed s/'\\_'/'\\\\\\_'/g \
|
||||
| sed s/'`_`'/'`\\\\_`'/g \
|
||||
| sed s/'`\\`'/'`\\\\`'/g \
|
||||
| sed s/'`\\\\`'/'`\\\\\\\\`'/g \
|
||||
| sed s/'`\$`'/'`\\\\$`'/g \
|
||||
| sed s/'`\$\$`'/'`\\\\$$`'/g \
|
||||
| sed s/'`\*`'/'`\\*`'/g \
|
||||
| sed s/'`\*\*`'/'`\\*\\*`'/g \
|
||||
> /tmp/"${name}".md
|
||||
# Now we have a pure Markdown file (at least we hope)
|
||||
|
||||
title="$(grep -o -m 1 "<title>[^<]*</title>" "${input}" | grep -o ">.*<" | sed s/">"/""/ | sed s/"<"/""/)"
|
||||
echo -e "${cyan}I found this as a possible title${white} : $u${title}$U." | tee -a /tmp/strapdown2pdf.log
|
||||
|
||||
if [ X"${htm}" = "Xtrue" ]; then
|
||||
echo -e "<!DOCTYPE html><html><head><meta charset=\"utf-8\"/><title>${title}</title></head>\n<body>" > "${name}".htm
|
||||
python -m markdown -e utf8 -v /tmp/"${name}".md >> "${name}".htm
|
||||
echo -e "</body>\n</html>\n" >> "${name}".htm
|
||||
echo -e "${cyan}I am done producing ${name}.htm in the current repertory."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Convert md -> tex with lunamark (in /tmp/, as always)
|
||||
lunamark -Xhash_enumerators -t latex -o "${name}".tex~ /tmp/"${name}".md || exit 21
|
||||
|
||||
# Because we are proud of this script
|
||||
echo -e "%% -*- coding:utf8; mode:latex -*-\n%% LaTeX file automatically generated with [strapdown2pdf](https://bitbucket.org/lbesson/bin/src/master/strapdown2pdf)" > "${name}".tex
|
||||
echo -e "%% from ${p}/${input}, the $(date)." >> "${name}".tex
|
||||
|
||||
# Adding two autotex specials comments,
|
||||
# One for the title
|
||||
echo -e "%autotex% Titre: ${title}" >> "${name}".tex
|
||||
# And one for the scale
|
||||
echo -e "%autotex% Scale: ${scale}" >> "${name}".tex
|
||||
# And one for the police size
|
||||
echo -e "%autotex% PoliceSize: ${policesize}" >> "${name}".tex
|
||||
|
||||
# We add the .tex file (it does NOT have any LaTeX headers)
|
||||
# Apparently, I have been able to remove all weird espaced math LaTeX code in the input file ...
|
||||
|
||||
# FIXME: here we should also try to improve the LaTeX math code preservation
|
||||
cat "${name}".tex~ \
|
||||
| sed s/'\\\$'/$/g \
|
||||
| sed s/'\\^'/'^'/g \
|
||||
| sed s/'\\char92{}'/'\\'/g \
|
||||
| sed s/'\\char62{}'/'>'/g \
|
||||
| sed s/'\\char60{}'/'<'/g \
|
||||
| sed s/'\\char126{}'/'\~'/g \
|
||||
| sed s/'\\{'/'{'/g \
|
||||
| sed s/'\\}'/'}'/g \
|
||||
| sed s/'\\_'/'_'/g \
|
||||
| sed s/'\\_{'/'_{'/g \
|
||||
| sed s/'\\_'/'_'/g \
|
||||
| sed s/'\\emph'/''/g \
|
||||
| sed 's/\\&/\&/g' \
|
||||
| sed s/'\^{}'/'^'/g \
|
||||
| sed s/'\"\([^"]*\)\"'/'« \1 »'/g \
|
||||
| sed s/'\([A-Za-z]\)_\([A-Za-z]\)'/'\1\\_\2'/g \
|
||||
| sed s_'\(\\href{http[^}]*}\){\([^} ]*\.[^} ]*\)}'_'\1{\\texttt{\2}}'_g \
|
||||
| sed s/'\(\\[a-z]*section\){'/'\1*{'/g \
|
||||
>> "${name}".tex || exit 16
|
||||
# FIXME Add '\([^}]*\)' between on the left and right on {\([^} ]*\.[^} ]*\)} after { and before } ?
|
||||
|
||||
# And a final line to say "Compiled from HTML/MarkDown with StrapDown.js to PDF with ..."
|
||||
if [ "$discrete" != "true" ]; then
|
||||
echo -e "\n\n\n\n%% Added with strapdown2pdf\n\\\\hspace{\\\\fill}\n\\\\vfill{}\n\n\\\\hspace{\\\\fill}\\\\rule{.6\\\\linewidth}{0.4pt}\\\\hspace{\\\\fill}\n\n\\\\begin{quote}\n\\\\begin{footnotesize}\n (Compiled to \\\\textbf{PDF} from a \\\\texttt{HTML/Markdown} file (powered by \\\\href{http://lbesson.bitbucket.org/md/}{\\\\texttt{StrapDown.js}}) with \\\\textbf{\\\\href{http://lbesson.bitbucket.org/md/strapdown2pdf.html}{strapdown2pdf}}, \\\\texttt{v${version}}.)\n\\\\end{footnotesize}\n\\\\end{quote}\n" >> "${name}".tex
|
||||
fi
|
||||
|
||||
# Compile in batchmode it with autotex, to automatically add headers and packages stuff
|
||||
${AUTOTEX} "${name}".tex
|
||||
|
||||
# Compress it (and even gpg sign it !)
|
||||
if [ "$sign" = "true" ]; then
|
||||
PDFCompress --sign "${name}".pdf
|
||||
else
|
||||
PDFCompress "${name}".pdf
|
||||
fi
|
||||
|
||||
# Clean up local repertory
|
||||
mv -vf "${name}".tex* /tmp/
|
||||
if [ "$keep" = "true" ]; then
|
||||
cp -vf /tmp/"${name}".tex ./ && \
|
||||
echo -e "${green} The intermediate LaTeX file ${name}.tex has been kept here, as asked by the option -k or --keep."
|
||||
fi
|
||||
|
||||
# Proudly say that we are done
|
||||
echo -e "${green}The file ${name}.pdf have been well generated from ${input}, and it should be really beautiful :)" | tee -a /tmp/strapdown2pdf.log
|
||||
# read
|
||||
}
|
||||
|
||||
log="/tmp/strapdown2pdf.log"
|
||||
# And finally treat every arguments.
|
||||
if [ "$quiet" = "true" ]; then
|
||||
echo -e "On "$(date)", strapdown2pdf is running on quiet mode." > "${log}"
|
||||
echo -e "On quiet mode, arguments were '$@'." &>> "${log}"
|
||||
StrapDown2PDF "${1}" &>> "${log}"
|
||||
shift
|
||||
for finput in "$@"; do
|
||||
echo -e "\n\n---------------------------" &>> "${log}"
|
||||
echo -e "Generating the next file..." &>> "${log}"
|
||||
StrapDown2PDF "${finput}" &>> "${log}"
|
||||
done
|
||||
else
|
||||
StrapDown2PDF "${1}"
|
||||
shift
|
||||
for finput in "$@"; do
|
||||
echo -e "\n\n---------------------------"
|
||||
echo -e "${blue}Generating the next file..."
|
||||
StrapDown2PDF "${finput}"
|
||||
done
|
||||
fi
|
||||
|
||||
## END
|
125
strapdown2pdf.htm
Normal file
125
strapdown2pdf.htm
Normal file
@@ -0,0 +1,125 @@
|
||||
<!DOCTYPE html><html><head><meta charset="utf-8"/><title>StrapDown2PDF</title></head>
|
||||
<body>
|
||||
<blockquote>
|
||||
<h3>Please, before reading this page, be sure to know what <a href="http://lbesson.bitbucket.org/md/" title="Homepage of StrapDown.js !">StrapDown.js</a> is</h3>
|
||||
<p>Check out <a href="http://lbesson.bitbucket.org/md/index.html" title="Explanations on StrapDown.js !">index.html</a> if you don't know yet how cool <a href="http://lbesson.bitbucket.org/md/" title="Homepage of StrapDown.js !">StrapDown.js</a> is !</p>
|
||||
</blockquote>
|
||||
<hr />
|
||||
<h1>StrapDown2PDF</h1>
|
||||
<p><a href="http://lbesson.bitbucket.org/md/strapdown2pdf" title="A super cool Bash script !">StrapDown2PDF</a> is a <strong>super cool</strong> Bash script designed to print a <em>StrapDown</em>-powered web-page to a PDF document.</p>
|
||||
<h2>More details</h2>
|
||||
<p>To be more precise, <a href="http://lbesson.bitbucket.org/md/" title="Homepage of StrapDown.js !">StrapDown.js</a> allows you to write pretty HTML pages with the Markdown syntax (more details here <a href="http://lbesson.bitbucket.org/md/index.html" title="Explanations on StrapDown.js !">index.html</a>).</p>
|
||||
<p>And <a href="http://lbesson.bitbucket.org/md/strapdown2pdf" title="A super cool Bash script !">StrapDown2PDF</a> can be used (on your laptop, from the command line) to transform the document from HTML (writen with Markdown) to PDF (with one intermediate phasis as a LaTeX file).</p>
|
||||
<hr />
|
||||
<h2>Example and how-to</h2>
|
||||
<p><a href="strapdown2pdf.pdf">This page as a PDF</a> is a pretty good example of an automatically compiled PDF file.</p>
|
||||
<p><strong>Warning:</strong> this script is <em>still experimental</em>: the compilation is never perfect.
|
||||
It is advisable to use the <code>-keep</code> option, change a little bit the LaTeX file and then compile again.</p>
|
||||
<h3>How-to ?</h3>
|
||||
<p>You just have to use this command, in a terminal:</p>
|
||||
<blockquote>
|
||||
<p><code>bash
|
||||
$ strapdown2pdf MyWebPage.html # This will produce "MyWebPage.pdf"</code></p>
|
||||
</blockquote>
|
||||
<h3>More than one file at a time ?</h3>
|
||||
<p><strong>strapdown2pdf</strong> even supports multi arguments.
|
||||
For instance, the following command will print to PDF every <a href="http://lbesson.bitbucket.org/md/" title="Homepage of StrapDown.js !">StrapDown.js</a>-flavored HTML file in the current directory:</p>
|
||||
<blockquote>
|
||||
<p><code>bash
|
||||
$ echo "Calling 'strapdown2pdf *.html' will produce a PDF for every .html document in the current directory."
|
||||
$ strapdown2pdf *.html</code></p>
|
||||
</blockquote>
|
||||
<hr />
|
||||
<h3>Even more details?</h3>
|
||||
<p><strong>strapdown2pdf</strong> comes with a basic help included ! Just ask with option <code>-h</code> (as always):</p>
|
||||
<blockquote>
|
||||
<p>```bash
|
||||
$ strapdown2pdf -h
|
||||
strapdown2pdf -help | [options]</p>
|
||||
<p>Print a StrapDown-powered web-page to a PDF document, using lunamark and autotex.</p>
|
||||
<p>Help:
|
||||
-h to print this help message (and quit).
|
||||
-v to print just the version of strapdown2pdf (and quit).</p>
|
||||
<p>Options:
|
||||
-i|-interactive run PDFLaTeX with the interactive (errorstopmode) mode (default is batchmode).
|
||||
-q|-quiet run strapdown2pdf in quiet mode (no output at all, everything is redirected to /tmp/strapdown2pdf.log).
|
||||
-m|-htm run strapdown2pdf to produce a simple HTML file (which do not use StrapDown.js), written to a .htm file.
|
||||
For important document, producing a .htm autonomous file is a good idea.
|
||||
-d|-discrete run strapdown2pdf is discrete mode, without adding any creditentials in the produced document.
|
||||
-s[0-9][0-9]<em>% change the default scale used by autotex (default is 85%, '-70%', '-75%' or '-80%' are good also) New!
|
||||
-[0-9][0-9]</em>pt change the default police size used by autotex (default is 11pt, '-10pt' or '-12pt' are good also) New!
|
||||
-k|-keep keep the intermediate .tex file. New!
|
||||
-s|-sign sign the produce PDF document with GnuPG (thanks to PDFCompress).</p>
|
||||
<p>strapdown2pdf v0.8 : Copyrights: (c) Lilian Besson 2011-2014.
|
||||
Released under the term of the GPL v3 Licence (more details on http://besson.qc.to/LICENSE.html).
|
||||
In particular, strapdown2pdf is provided WITHOUT ANY WARANTY.
|
||||
```</p>
|
||||
</blockquote>
|
||||
<h3>Options</h3>
|
||||
<p><strong>strapdown2pdf</strong> now comes with these options:</p>
|
||||
<ul>
|
||||
<li><code>-interactive</code> (shortcut is <code>-i</code>) to run <a href="http://besson.qc.to/bin/pdflatex">PDFLaTeX</a> with the interactive (errorstopmode) mode (default is batchmode),</li>
|
||||
<li><code>-quiet</code> (shortcut is <code>-q</code>) to run <a href="http://lbesson.bitbucket.org/md/strapdown2pdf.html">strapdown2pdf</a> in quiet mode (no output at all, everything is redirected to <code>/tmp/strapdown2pdf.log</code>),</li>
|
||||
<li><code>-htm</code> (shortcut is <code>-m</code>) to produce a simple HTML file (which do not use StrapDown.js, see <a href="./strapdown2pdf.htm">this example strapdown2pdf.htm</a>), written to a .htm file. For important document, producing a .htm autonomous file is a good idea,</li>
|
||||
<li><code>-discrete</code> (shortcut is <code>-d</code>) to run strapdown2pdf is discrete mode, without adding any creditentials in the produced document,</li>
|
||||
<li><code>-s[0-9][0-9]*%</code> (e.g. <code>-79%</code>) to change the default scale used by autotex (default is 85%, '-70%', '-75%' or '-80%' are good also),</li>
|
||||
<li><code>-[0-9][0-9]*pt</code> (e.g. <code>-10pt</code>) to change the default police size used by autotex (default is 11pt, '-10pt' or '-12pt' are good also),</li>
|
||||
<li><code>-keep</code> (shortcut is <code>-k</code>) to keep the intermediate <code>.tex</code> file,</li>
|
||||
<li><code>-sign</code> (shortcut is <code>-s</code>) to sign the produce PDF document with GnuPG (thanks to <a href="http://besson.qc.to/bin/PDFCompress">PDFCompress</a> option <code>--sign</code>).</li>
|
||||
</ul>
|
||||
<hr />
|
||||
<h2>Mandatory requirements</h2>
|
||||
<ul>
|
||||
<li><a href="http://jgm.github.io/lunamark/lunamark.1.html">lunamark</a> (an awesome <em>lua</em>-powered Markdown to LaTeX processor),</li>
|
||||
<li><a href="http://besson.qc.to/bin/autotex">autotex</a> (from my web page, or from <a href="https://bitbucket.org/lbesson/bin/src/master/autotex">bin/autotex</a>).</li>
|
||||
</ul>
|
||||
<h2>Optionnal requirements</h2>
|
||||
<p>These external scripts are not really mandatory, you could do without it by modifying a couple of lines of the script's code:</p>
|
||||
<ul>
|
||||
<li><a href="http://besson.qc.to/bin/PDFCompress">PDFCompress</a> (from my web page, or from <a href="https://bitbucket.org/lbesson/bin/src/master/PDFCompress">bin/PDFCompress</a>),</li>
|
||||
<li><a href="http://besson.qc.to/bin/pdflatex">pdflatex</a> (from my web page, or from <a href="https://bitbucket.org/lbesson/bin/src/master/pdflatex">bin/pdflatex</a>).</li>
|
||||
</ul>
|
||||
<hr />
|
||||
<h1>Future features ?</h1>
|
||||
<h3>A 100% perfect support for embeded LaTeX code</h3>
|
||||
<p>These two examples (<a href="example3.html">3</a> and <a href="example4.html">4</a>) show how to include <a href="http://www.mathjax.org/">MathJax</a>
|
||||
in a <em>StrapDown</em>-flavored HTML page to simply embed some <em>LaTeX</em> equations.</p>
|
||||
<blockquote>
|
||||
<p>Apparently, now <em>strapdown2pdf</em> have a better support for any (not too complicated) $\LaTeX{}$ code embedded in the <em>Markdown</em> source.
|
||||
Any feedback is welcome, and I will continue to improve this feature.</p>
|
||||
</blockquote>
|
||||
<h3>Some examples of a good PDF printed version of a StrapDown.js powered page</h3>
|
||||
<blockquote>
|
||||
<p>These are from September, October and November 2014.</p>
|
||||
</blockquote>
|
||||
<ul>
|
||||
<li><a href="http://perso.crans.org/besson/publis/10_10_2014__Liberation.en.html">This (English) translation of a French press article</a> about <a href="http://www.mahindraecolecentrale.edu.in/discover.html">Mahindra École Centrale</a>, nicely printed to <a href="http://perso.crans.org/besson/publis/10_10_2014__Liberation.en.pdf">this PDF</a>,</li>
|
||||
<li><a href="http://perso.crans.org/besson/publis/29_10_2014__LeMonde.en.html">This (English) translation of another French press article</a> about the future <a href="http://www.centrale-casablanca.ma/site/home.html">École Centrale Casablanca</a>, nicely printed to <a href="http://perso.crans.org/besson/publis/29_10_2014__LeMonde.en.pdf">a PDF, quickly modified by hand to include an image</a>,</li>
|
||||
<li><a href="http://perso.crans.org/besson/publis/PDE_09_2014/index.html">This small (French) research report</a> on a <a href="https://en.wikipedia.org/wiki/Partial_differential_equations">non-linear Partial Differential Equation</a>, nicely printed to <a href="http://perso.crans.org/besson/publis/PDE_09_2014/index.pdf">a PDF, with very good support of LaTeX</a> (<a href="https://bitbucket.org/lbesson/bin/diff/strapdown2pdf?diff2=20fd4babc524&at=master">since this modification</a>),</li>
|
||||
<li><a href="http://perso.crans.org/besson/agreg/m/2/">This (French) homepage of a programming project</a> on <a href="https://en.wikipedia.org/wiki/Eulerian_path#Properties">Euler theorems on Eulerian path</a>. I did this as an assignement for <a href="http://perso.crans.org/besson/cv.en.pdf">my M.Sc. of Computer Science in 2014</a>, and it was also a good training for one oral exam of the <a href="https://en.wikipedia.org/wiki/Agr%C3%A9gation">French national competitive examination to become a prep' school professor</a> in Mathematics and Computer Science (for <a href="http://web.archive.org/web/20140709144720/agreg.org/ResultatsMerite2014.html">which I have been ranked 23rd among 795</a> in 2014!).</li>
|
||||
</ul>
|
||||
<hr />
|
||||
<h3>Autocompile on the fly ?</h3>
|
||||
<p>Make a version "on the browser" ?
|
||||
Something like, if <a href="http://lbesson.bitbucket.org/md/index.html" title="Explanations on StrapDown.js !">index.html</a> uses <a href="http://lbesson.bitbucket.org/md/" title="Homepage of StrapDown.js !">StrapDown.js</a>, then <a href="index.html?pdf">index.html?pdf</a> can be the same HTML page,
|
||||
but using javascript (like <a href="https://github.com/manuels/texlive.js/">texlive.js</a>)
|
||||
to autoproduce a PDF version of the page in the background, asking to download it when it is done.</p>
|
||||
<p><a href="http://manuels.github.io/texlive.js">An example is there</a>. It is so cool I want to use it :)</p>
|
||||
<h3>Add a "Compile to PDF with TeXLive" button in StrapDown theme</h3>
|
||||
<p>I added a <a href="http://lbesson.bitbucket.org/squirt/">Squirt</a> button
|
||||
to the two <a href="http://lbesson.bitbucket.org/md/" title="Homepage of StrapDown.js !">StrapDown.js</a> theme, and therefore I guess
|
||||
it could be possible to do the same for a "Compile to PDF with TeXLive" button !</p>
|
||||
<hr />
|
||||
<h1>About</h1>
|
||||
<h3>Hacked by <a href="https://bitbucket.org/lbesson">Lilian Besson</a></h3>
|
||||
<h3>Languages</h3>
|
||||
<ul>
|
||||
<li>GNU Bash v4+ for the script,</li>
|
||||
<li>Markdown and <a href="http://lbesson.bitbucket.org/md/" title="Homepage of StrapDown.js !">StrapDown.js</a> for this page.</li>
|
||||
</ul>
|
||||
<h3>License</h3>
|
||||
<p>This project is released under the <strong>GPLv3 license</strong>, for more details,
|
||||
take a look at the <a href="http://besson.qc.to/LICENSE.html">LICENSE</a> file in the source.</p>
|
||||
<p><em>Basically, that allow you to use all or part of the project for you own business.</em></p></body>
|
||||
</html>
|
||||
|
146
strapdown2pdf.html
Normal file
146
strapdown2pdf.html
Normal file
@@ -0,0 +1,146 @@
|
||||
<!DOCTYPE html><html><head><meta charset="utf-8"/><title>StrapDown2PDF</title></head><body><xmp theme="united">
|
||||
> ### Please, before reading this page, be sure to know what [StrapDown.js][] is
|
||||
> Check out [index.html][] if you don't know yet how cool [StrapDown.js][] is !
|
||||
|
||||
---
|
||||
|
||||
[StrapDown.js]: http://lbesson.bitbucket.org/md/ "Homepage of StrapDown.js !"
|
||||
[index.html]: http://lbesson.bitbucket.org/md/index.html "Explanations on StrapDown.js !"
|
||||
[StrapDown2PDF]: http://lbesson.bitbucket.org/md/strapdown2pdf "A super cool Bash script !"
|
||||
|
||||
# StrapDown2PDF
|
||||
[StrapDown2PDF][] is a **super cool** Bash script designed to print a *StrapDown*-powered web-page to a PDF document.
|
||||
|
||||
## More details
|
||||
To be more precise, [StrapDown.js][] allows you to write pretty HTML pages with the Markdown syntax (more details here [index.html][]).
|
||||
|
||||
And [StrapDown2PDF][] can be used (on your laptop, from the command line) to transform the document from HTML (writen with Markdown) to PDF (with one intermediate phasis as a LaTeX file).
|
||||
|
||||
---
|
||||
|
||||
## Example and how-to
|
||||
[This page as a PDF](strapdown2pdf.pdf) is a pretty good example of an automatically compiled PDF file.
|
||||
|
||||
**Warning:** this script is *still experimental*: the compilation is never perfect.
|
||||
It is advisable to use the `-keep` option, change a little bit the LaTeX file and then compile again.
|
||||
|
||||
### How-to ?
|
||||
You just have to use this command, in a terminal:
|
||||
|
||||
> ```bash
|
||||
> $ strapdown2pdf MyWebPage.html # This will produce "MyWebPage.pdf"
|
||||
> ```
|
||||
|
||||
### More than one file at a time ?
|
||||
**strapdown2pdf** even supports multi arguments.
|
||||
For instance, the following command will print to PDF every [StrapDown.js][]-flavored HTML file in the current directory:
|
||||
|
||||
> ```bash
|
||||
> $ echo "Calling 'strapdown2pdf *.html' will produce a PDF for every .html document in the current directory."
|
||||
> $ strapdown2pdf *.html
|
||||
> ```
|
||||
|
||||
---
|
||||
|
||||
### Even more details?
|
||||
**strapdown2pdf** comes with a basic help included ! Just ask with option `-h` (as always):
|
||||
|
||||
> ```bash
|
||||
> $ strapdown2pdf -h
|
||||
> strapdown2pdf -help | [options]
|
||||
>
|
||||
> Print a StrapDown-powered web-page to a PDF document, using lunamark and autotex.
|
||||
>
|
||||
> Help:
|
||||
> -h to print this help message (and quit).
|
||||
> -v to print just the version of strapdown2pdf (and quit).
|
||||
>
|
||||
> Options:
|
||||
> -i|-interactive run PDFLaTeX with the interactive (errorstopmode) mode (default is batchmode).
|
||||
> -q|-quiet run strapdown2pdf in quiet mode (no output at all, everything is redirected to /tmp/strapdown2pdf.log).
|
||||
> -m|-htm run strapdown2pdf to produce a simple HTML file (which do not use StrapDown.js), written to a .htm file.
|
||||
> For important document, producing a .htm autonomous file is a good idea.
|
||||
> -d|-discrete run strapdown2pdf is discrete mode, without adding any creditentials in the produced document.
|
||||
> -s[0-9][0-9]*% change the default scale used by autotex (default is 85%, '-70%', '-75%' or '-80%' are good also) New!
|
||||
> -[0-9][0-9]*pt change the default police size used by autotex (default is 11pt, '-10pt' or '-12pt' are good also) New!
|
||||
> -k|-keep keep the intermediate .tex file. New!
|
||||
> -s|-sign sign the produce PDF document with GnuPG (thanks to PDFCompress).
|
||||
>
|
||||
> strapdown2pdf v0.8 : Copyrights: (c) Lilian Besson 2011-2014.
|
||||
> Released under the term of the GPL v3 Licence (more details on http://besson.qc.to/LICENSE.html).
|
||||
> In particular, strapdown2pdf is provided WITHOUT ANY WARANTY.
|
||||
> ```
|
||||
|
||||
### Options
|
||||
**strapdown2pdf** now comes with these options:
|
||||
|
||||
+ `-interactive` (shortcut is `-i`) to run [PDFLaTeX](http://besson.qc.to/bin/pdflatex) with the interactive (errorstopmode) mode (default is batchmode),
|
||||
+ `-quiet` (shortcut is `-q`) to run [strapdown2pdf](http://lbesson.bitbucket.org/md/strapdown2pdf.html) in quiet mode (no output at all, everything is redirected to `/tmp/strapdown2pdf.log`),
|
||||
+ `-htm` (shortcut is `-m`) to produce a simple HTML file (which do not use StrapDown.js, see [this example strapdown2pdf.htm](./strapdown2pdf.htm)), written to a .htm file. For important document, producing a .htm autonomous file is a good idea,
|
||||
+ `-discrete` (shortcut is `-d`) to run strapdown2pdf is discrete mode, without adding any creditentials in the produced document,
|
||||
+ `-s[0-9][0-9]*%` (e.g. `-79%`) to change the default scale used by autotex (default is 85%, '-70%', '-75%' or '-80%' are good also),
|
||||
+ `-[0-9][0-9]*pt` (e.g. `-10pt`) to change the default police size used by autotex (default is 11pt, '-10pt' or '-12pt' are good also),
|
||||
+ `-keep` (shortcut is `-k`) to keep the intermediate `.tex` file,
|
||||
+ `-sign` (shortcut is `-s`) to sign the produce PDF document with GnuPG (thanks to [PDFCompress](http://besson.qc.to/bin/PDFCompress) option `--sign`).
|
||||
|
||||
---
|
||||
|
||||
## Mandatory requirements
|
||||
+ [lunamark](http://jgm.github.io/lunamark/lunamark.1.html) (an awesome *lua*-powered Markdown to LaTeX processor),
|
||||
+ [autotex](http://besson.qc.to/bin/autotex) (from my web page, or from [bin/autotex](https://bitbucket.org/lbesson/bin/src/master/autotex)).
|
||||
|
||||
## Optionnal requirements
|
||||
These external scripts are not really mandatory, you could do without it by modifying a couple of lines of the script's code:
|
||||
|
||||
+ [PDFCompress](http://besson.qc.to/bin/PDFCompress) (from my web page, or from [bin/PDFCompress](https://bitbucket.org/lbesson/bin/src/master/PDFCompress)),
|
||||
+ [pdflatex](http://besson.qc.to/bin/pdflatex) (from my web page, or from [bin/pdflatex](https://bitbucket.org/lbesson/bin/src/master/pdflatex)).
|
||||
|
||||
---
|
||||
|
||||
# Future features ?
|
||||
### A 100% perfect support for embeded LaTeX code
|
||||
These two examples ([3](example3.html) and [4](example4.html)) show how to include [MathJax](http://www.mathjax.org/)
|
||||
in a *StrapDown*-flavored HTML page to simply embed some *LaTeX* equations.
|
||||
|
||||
> Apparently, now *strapdown2pdf* have a better support for any (not too complicated) $\LaTeX{}$ code embedded in the *Markdown* source.
|
||||
> Any feedback is welcome, and I will continue to improve this feature.
|
||||
|
||||
### Some examples of a good PDF printed version of a StrapDown.js powered page
|
||||
> These are from September, October and November 2014.
|
||||
|
||||
- [This (English) translation of a French press article](http://perso.crans.org/besson/publis/10_10_2014__Liberation.en.html) about [Mahindra École Centrale](http://www.mahindraecolecentrale.edu.in/discover.html), nicely printed to [this PDF](http://perso.crans.org/besson/publis/10_10_2014__Liberation.en.pdf),
|
||||
- [This (English) translation of another French press article](http://perso.crans.org/besson/publis/29_10_2014__LeMonde.en.html) about the future [École Centrale Casablanca](http://www.centrale-casablanca.ma/site/home.html), nicely printed to [a PDF, quickly modified by hand to include an image](http://perso.crans.org/besson/publis/29_10_2014__LeMonde.en.pdf),
|
||||
- [This small (French) research report](http://perso.crans.org/besson/publis/PDE_09_2014/index.html) on a [non-linear Partial Differential Equation](https://en.wikipedia.org/wiki/Partial_differential_equations), nicely printed to [a PDF, with very good support of LaTeX](http://perso.crans.org/besson/publis/PDE_09_2014/index.pdf) ([since this modification](https://bitbucket.org/lbesson/bin/diff/strapdown2pdf?diff2=20fd4babc524&at=master)),
|
||||
- [This (French) homepage of a programming project](http://perso.crans.org/besson/agreg/m/2/) on [Euler theorems on Eulerian path](https://en.wikipedia.org/wiki/Eulerian_path#Properties). I did this as an assignement for [my M.Sc. of Computer Science in 2014](http://perso.crans.org/besson/cv.en.pdf), and it was also a good training for one oral exam of the [French national competitive examination to become a prep' school professor](https://en.wikipedia.org/wiki/Agr%C3%A9gation) in Mathematics and Computer Science (for [which I have been ranked 23rd among 795](http://web.archive.org/web/20140709144720/agreg.org/ResultatsMerite2014.html) in 2014!).
|
||||
|
||||
---
|
||||
|
||||
### Autocompile on the fly ?
|
||||
Make a version "on the browser" ?
|
||||
Something like, if [index.html][] uses [StrapDown.js][], then [index.html?pdf](index.html?pdf) can be the same HTML page,
|
||||
but using javascript (like [texlive.js](https://github.com/manuels/texlive.js/))
|
||||
to autoproduce a PDF version of the page in the background, asking to download it when it is done.
|
||||
|
||||
[An example is there](http://manuels.github.io/texlive.js). It is so cool I want to use it :)
|
||||
|
||||
### Add a "Compile to PDF with TeXLive" button in StrapDown theme
|
||||
I added a [Squirt](http://lbesson.bitbucket.org/squirt/) button
|
||||
to the two [StrapDown.js][] theme, and therefore I guess
|
||||
it could be possible to do the same for a "Compile to PDF with TeXLive" button !
|
||||
|
||||
---
|
||||
|
||||
# About
|
||||
### Hacked by [Lilian Besson](https://bitbucket.org/lbesson)
|
||||
|
||||
### Languages
|
||||
+ GNU Bash v4+ for the script,
|
||||
+ Markdown and [StrapDown.js][] for this page.
|
||||
|
||||
### License
|
||||
This project is released under the **GPLv3 license**, for more details,
|
||||
take a look at the [LICENSE](http://besson.qc.to/LICENSE.html) file in the source.
|
||||
|
||||
*Basically, that allow you to use all or part of the project for you own business.*
|
||||
|
||||
</xmp><script type="text/javascript" src="strapdown.min.js"></script></body></html>
|
BIN
strapdown2pdf.pdf
Normal file
BIN
strapdown2pdf.pdf
Normal file
Binary file not shown.
Reference in New Issue
Block a user