The most difficult problem I ran into with this is the conditional styling of different sections and the conditional numbering of different sections. This is a solution for both of these problems.
Here is my paper:
#+TITLE: Complex Tracking of Awesome Things
#+AUTHOR: Bastibe
#+INCLUDE: style.org
* Abstract
:PROPERTIES:
:NUMBERS: no
:HTML_CONTAINER_CLASS: abstract
:END:
Lorem ipsum dolor sit amet...
* Introduction
:PROPERTIES:
:NUMBERS: no
:END:
* Methodology
* Results
* Conclusion
* Acknowledgements
:PROPERTIES:
:NUMBERS: no
:END:
First up, this includes an org file with some additional options. This file, called style.org
above sets the HTML export to load a custom style sheet, and sets a few LaTeX options. If you are not exporting to LaTeX, you won't need those.
#+LANGUAGE: en
#+OPTIONS: tags:nil html-postamble:nil # toc:nil
#+STARTUP: nofold hideblocks
#+BIND: org-latex-title-command ""
#+HTML_MATHJAX: path:"MathJax/MathJax.js"
#+HTML_HEAD: <link rel="stylesheet" type="text/css" href="style.css" />
#+LATEX_CLASS: article
#+LATEX_CLASS_OPTIONS: [a4paper, 12pt]
#+LATEX_HEADER: \usepackage{setspace}
#+LATEX_HEADER: \onehalfspacing
#+LATEX_HEADER: \usepackage{fontspec}
#+LATEX_HEADER: \setmainfont{Cambria}
#+LATEX_HEADER: \setmonofont{PragmataPro}
#+LATEX_HEADER: \usepackage{polyglossia}
#+LATEX_HEADER: \setdefaultlanguage{english}
#+LATEX_HEADER: \usepackage[a4paper, scale=0.8]{geometry}
#+LATEX_HEADER: \usepackage{amsmath}
#+LATEX_HEADER: \usepackage{units}
#+LATEX_HEADER: \usepackage{titling}
#+LATEX_HEADER: \usepackage{listings}
#+LATEX_HEADER: \lstset{basicstyle=\ttfamily\footnotesize,showstringspaces=false}
#+LATEX_HEADER: \usepackage[hang]{caption}
In order to render this as paper-like HTML, a little CSS is enough (saved in style.css
:
#content {
max-width: 80ex;
position: relative;
margin: 5px auto;
font-family: Cambria;
text-align: justify;
-moz-hyphens: auto;
}
.abstract {
max-width: 65ex;
margin: 5px auto;
margin-top: 4em;
margin-bottom: 4em;
content: none;
}
p {
text-indent: 5ex;
margin-bottom: 0;
margin-top: 0;
}
However, the section numbers will be wrong. Org mode can either number all sections, or none. Papers typically need numbers on the body sections, but not the Abstract and the Summary. The following piece of code will make Org put numbers in front of regular sections, but suppress the numbers if the property :NUMBERS: no
is set:
(defun headline-numbering-filter (data backend info)
"No numbering in headlines that have a property :numbers: no"
(let* ((beg (next-property-change 0 data))
(headline (if beg (get-text-property beg :parent data))))
(if (string= (org-element-property :NUMBERS headline) "no")
(cond ((eq backend 'latex)
(replace-regexp-in-string
"\\(part\\|chapter\\|\\(?:sub\\)*section\\|\\(?:sub\\)?paragraph\\)"
"\\1*" data nil nil 1))
((eq backend 'html)
(replace-regexp-in-string
"\\(<h[1-6]\\)\\([^>]*>\\)"
"\\1 class=\"nonumber\"\\2" data nil nil)))
data)))
(setq org-export-filter-headline-functions '(headline-numbering-filter))
This works well for the LaTeX export, but not in the HTML export. With modern CSS, browsers can do the numbering for you though (appended to style.css
):
/* do not show section numbers */
span.section-number-2 { display: none; }
span.section-number-3 { display: none; }
span.section-number-4 { display: none; }
span.section-number-5 { display: none; }
span.section-number-6 { display: none; }
/* use LaTeX-style names for the counters */
h1 { counter-reset: section; }
h2 { counter-reset: subsection; }
h3 { counter-reset: subsubsection; }
h4 { counter-reset: paragraph; }
h5 { counter-reset: subparagraph; }
.nonumber::before { content: none; }
h2::before {
content: counter(section) " ";
counter-increment: section;
}
h3::before {
content: counter(section) "." counter(subsection) " ";
counter-increment: subsection;
}
h4::before {
content: counter(section) "." counter(subsection) "." counter(subsubsection) " ";
counter-increment: subsubsection;
}
h5::before {
content: counter(section) "." counter(subsection) "." counter(subsubsection) "." counter(paragraph) " ";
counter-increment: paragraph;
}
h6::before {
content: counter(section) "." counter(subsection) "." counter(subsubsection) "." counter(paragraph) "." counter(subparagraph) " ";
counter-increment: subparagraph;
}
With that, you can export your paper to both LaTeX and HTML.
...
will be wrapped as<div class="abstract"><p>...</p></div>
. For having a LaTeX like title maybe you should fill a bug report. For now use the macro{{{AUTHOR}}}
and snippets@@html:whatever@@
to build what you want.