Skip to content

Instantly share code, notes, and snippets.

@holtzermann17
Last active April 19, 2021 23:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save holtzermann17/4bf00a023e9ba1d7fd38d02abd641b42 to your computer and use it in GitHub Desktop.
Save holtzermann17/4bf00a023e9ba1d7fd38d02abd641b42 to your computer and use it in GitHub Desktop.
Rendering Org files to HTML on post-receive hook
;; This doesn't do anything fancy, and right now it just prints
;; everything at the same level.
(load "/home/git/emacs-htmlize/htmlize.el")
(setenv "PATH" "/usr/local/texlive/2021/bin/x86_64-linux:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games")
(setq exec-path (append '("/usr/local/texlive/2021/bin/x86_64-linux") exec-path))
(org-babel-do-load-languages
'org-babel-load-languages
'((emacs-lisp .t)
(python . t)
(R . t)
(clojure . t)
(calc . t)
)
)
(setq org-confirm-babel-evaluate nil)
(setq org-export-use-babel nil)
(setq org-src-fontify-natively t)
(with-eval-after-load 'ox-html
(setq org-html-head
(replace-regexp-in-string
".org-svg { width: 90%; }"
".org-svg { width: auto; }"
org-html-style-default)))
(setq org-format-latex-options '(:foreground default :background default :scale 2 :html-foreground "Black" :html-background "Transparent" :html-scale 1.2 :matchers
("begin" "$1" "$" "$$" "\\(" "\\[")))
(setq org-preview-latex-process-alist
'((dvipng :programs
("latex" "dvipng")
:description "dvi > png" :message "you need to install the programs: latex and dvipng." :image-input-type "dvi" :image-output-type "png" :image-size-adjust
(1.0 . 1.0)
:latex-compiler
("latex -interaction nonstopmode -output-directory %o %f")
:image-converter
("dvipng -D %D -T tight -o %O %f"))
(dvisvgm :programs
("latex" "dvisvgm")
:description "dvi > svg"
:message "you need to install the programs: latex and dvisvgm."
:image-input-type "dvi" :image-output-type "svg"
:image-size-adjust (1.7 . 1.0)
:latex-compiler
("latex -interaction nonstopmode -output-directory %o %f")
:image-converter
("dvisvgm %f -n -e -c %S -o %O"))
(imagemagick :programs
("latex" "convert")
:description "pdf > png" :message "you need to install the programs: latex and imagemagick." :image-input-type "pdf" :image-output-type "png" :image-size-adjust
(1.0 . 1.0)
:latex-compiler
("pdflatex -interaction nonstopmode -output-directory %o %f")
:image-converter
("convert -density %D -trim -antialias %f -quality 100 %O"))))
(setq org-format-latex-header
"\\documentclass{article}
\\usepackage[usenames]{color}
[PACKAGES]
[DEFAULT-PACKAGES]
\\pagestyle{empty} % do not remove
% The settings below are copied from fullpage.sty
\\setlength{\\textwidth}{\\paperwidth}
\\addtolength{\\textwidth}{-3cm}
\\setlength{\\oddsidemargin}{1.5cm}
\\addtolength{\\oddsidemargin}{-2.54cm}
\\setlength{\\evensidemargin}{\\oddsidemargin}
\\setlength{\\textheight}{\\paperheight}
\\addtolength{\\textheight}{-\\headheight}
\\addtolength{\\textheight}{-\\headsep}
\\addtolength{\\textheight}{-\\footskip}
\\addtolength{\\textheight}{-3cm}
\\setlength{\\topmargin}{1.5cm}
\\addtolength{\\topmargin}{-2.54cm}
\\usepackage{concmath}
")
(defun output ()
(let ((file-names (nthcdr 5 command-line-args)))
(princ (apply #'concat (mapcar
(lambda (fn)
(find-file fn)
(org-mode)
(org-html-export-to-html)
(concat fn " : has contents : " (buffer-substring-no-properties (point-min) (point-max))))
file-names)))))

MWE

Now there is some content in the README. And we’ll render it as org?

It should become visible on the web soon.

Here, it’s becoming a text file?

OK this should work now? Or? What does this mean?

Getting a bit complicated.

Starting to use xargs… got Emacs to run. Let’s see if we can get the contents. Does it work with multiple files? Should do… if I get the code right. ? Should be fine now.

Example

This is some R code. It should at least in principle show up with color enhancements… but we won’t evaluate it server side for now.

# Sample from the vector 'a' 1 element.
a<-c("a","b","c","d","e","f")
sample(a, 3)

This works now

This ~ is a test_of_the{codebox}

Some math

This is an unbiased estimator of $\overline{Y}$ with approximate variance:

$$\mathrm{V{\hat{a}}r} (\overline{y}\mathrm{post}) ≈ \frac{1-f}{n}∑ w_iS_i^2+\frac{1-f}{n}∑ W_i (1-W_i)\frac{S_i^2}{n_i} $$

Note that the first term on the right hand side of this expression would have been the variance of $\overline{y}\mathrm{post}$, had the sample been pre-stratified. The second term is always non-negative.

#! /bin/bash
emacs --batch -l ~/mwe.el --eval "(output)" "$@"
#!/bin/sh
GIT_WORK_TREE=/var/www/html/org-notes git checkout -f
cd /var/www/html/org-notes
git --git-dir=/home/git/org-notes.git --work-tree=/var/www/html/org-notes diff-tree --no-commit-id --name-only -r HEAD | xargs -I{} ~/mwe.sh {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment