使用组织模式设置HTML纸张格式


11

在HTML导出过程中,组织模式的默认设置是将作者置于页面底部的后记中。

但是我想导出一个文件,例如文档,作者在标题和摘要之间。是否可以以某种方式将作者放在标题之后?

并且可以将摘要标记为摘要吗?我已经使用了定界符

#+BEGIN_abstract
...
#+END_abstract

将文本标记为摘要,但将其呈现为普通段落(没有缩排之类的blockquote)。是否可以为摘要和局部标签获得正确的缩进?


2
对于抽象要求,请使用css。 ...将被包装为<div class="abstract"><p>...</p></div>。对于像LaTeX这样的标题,也许您应该填写错误报告。现在,使用宏{{{AUTHOR}}}和代码片段@@html:whatever@@构建所需的内容。
拉斯姆斯2015年

Answers:


10

也许是这样(经过LaTeX和HTML测试)

#+TITLE: An Orged Paper
#+AUTHOR: Rasmus
#+DATE: A Dark Day for Science 

#+RESULTS: html-header

#+begin_abstract
#+begin_center
{{{html-only(*Abstract*)}}}
#+end_center
my long abstract that is longer than one line. my long abstract that is longer than one line.
#+end_abstract
#+toc: headlines
* Introduction
Please read my paper!
* Data
~{0,1}~
* Conclusion
Something deep and profound

{{{html-only(------------)}}}
* styles                                                           :noexport:
#+HTML_HEAD_EXTRA: <style type="text/css">
#+HTML_HEAD_EXTRA: <!--
#+HTML_HEAD_EXTRA:   .header_title {font-size: 2em; font-weight: bold;}
#+HTML_HEAD_EXTRA:   .header_author {font-size: 1.5em; font-weight: bold;text-align:center;}
#+HTML_HEAD_EXTRA:   .header_date {text-align:center;}
#+HTML_HEAD_EXTRA:   .header_date .timestamp {font-size:1em; color:#000000;}
#+HTML_HEAD_EXTRA:   .abstract {max-width: 30em; margin-left: auto; margin-right: auto;}
#+HTML_HEAD_EXTRA: -->
#+HTML_HEAD_EXTRA: </style>

#+OPTIONS: toc:nil

#+MACRO: html-only (eval (if (org-export-derived-backend-p org-export-current-backend 'html) "$1" ""))

#+NAME: html-header
#+BEGIN_SRC emacs-lisp :results raw :exports (if (org-export-derived-backend-p org-export-current-backend 'html) "results" "none")
  "#+begin_header
  ,#+begin_header_author
  {{{AUTHOR}}}
  ,#+end_header_author
  ,#+begin_header_date
  {{{DATE}}}
  ,#+end_header_date
  ,#+end_header
"
#+END_SRC

请注意,html-header也可以通过生成org-html-preamble。还要注意,from org 8.3 org-latex-title-command可以用于将标题自定义为格式字符串。


2

看一下源代码,似乎没有选择的方法。

我不确定您真正想要什么,只需提供两种可能的方法:

  1. 只需添加一个#+BEGIN_HTML ... #+END_HTML块即可编写您想要的内容。(其中写入的内容将被视为完全HTML。)但是您可能需要添加#+OPTIONS: toc: nil禁用TOC或将作者置于TOC下。

  2. 重新定义导出功能并执行所需操作(注意第50〜52行),只需(require 'ox-html)在配置文件中放置以下代码即可:

      (defun org-html-template (contents info)
        "Return complete document string after HTML conversion.
      CONTENTS is the transcoded contents string.  INFO is a plist
      holding export options."
        (concat
         (when (and (not (org-html-html5-p info)) (org-html-xhtml-p info))
           (let ((decl (or (and (stringp org-html-xml-declaration)
                  org-html-xml-declaration)
                 (cdr (assoc (plist-get info :html-extension)
                     org-html-xml-declaration))
                 (cdr (assoc "html" org-html-xml-declaration))
    
                 "")))
             (when (not (or (eq nil decl) (string= "" decl)))
         (format "%s\n"
             (format decl
                 (or (and org-html-coding-system
                      (fboundp 'coding-system-get)
                      (coding-system-get org-html-coding-system 'mime-charset))
                     "iso-8859-1"))))))
         (org-html-doctype info)
         "\n"
         (concat "<html"
           (when (org-html-xhtml-p info)
             (format
              " xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"%s\" xml:lang=\"%s\""
              (plist-get info :language) (plist-get info :language)))
           ">\n")
         "<head>\n"
         (org-html--build-meta-info info)
         (org-html--build-head info)
         (org-html--build-mathjax-config info)
         "</head>\n"
         "<body>\n"
         (let ((link-up (org-trim (plist-get info :html-link-up)))
         (link-home (org-trim (plist-get info :html-link-home))))
           (unless (and (string= link-up "") (string= link-home ""))
             (format org-html-home/up-format
               (or link-up link-home)
               (or link-home link-up))))
         ;; Preamble.
         (org-html--build-pre/postamble 'preamble info)
         ;; Document contents.
         (format "<%s id=\"%s\">\n"
           (nth 1 (assq 'content org-html-divs))
           (nth 2 (assq 'content org-html-divs)))
         ;; Document title.
         (let ((title (plist-get info :title)))
           (format "<h1 class=\"title\">%s</h1>\n" (org-export-data (or title "") info)))
         ;; Author
         (let ((author (plist-get info :author)))
           (format "<h2 class=\"author\">%s</h2>\n" (org-export-data (or author "") info)))
         contents
         (format "</%s>\n"
           (nth 1 (assq 'content org-html-divs)))
         ;; Postamble.
         (org-html--build-pre/postamble 'postamble info)
         ;; Closing document.
         "</body>\n</html>"))        
    

3
这绝对是错误的方法!最好,您需要进行派生支持,查看org-export-define-derived-backend新模板并将其添加到中:translate-alist。有关具体示例,请参见ox-beamer.elox-koma-script.el例如ox-s5.el
拉斯姆斯2015年

1

我遇到的最困难的问题是不同部分的条件样式和不同部分的条件编号。这是针对这两个问题的解决方案。

这是我的论文:

#+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:

首先,它包括一个带有一些其他选项的组织文件。style.org上面称为此文件的文件设置HTML导出以加载自定义样式表,并设置一些LaTeX选项。如果您不导出到LaTeX,则不需要它们。

#+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}

为了将其呈现为纸质HTML,只需添加一些CSS(保存在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;
}

但是,段号将是错误的。组织模式可以为所有部分编号,也可以没有。论文的正文部分通常需要数字,但摘要和摘要则不需要。以下代码将使Org将数字放在常规部分的前面,但是如果:NUMBERS: no设置了此属性,则将数字隐藏起来:

(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))

这对于LaTeX导出效果很好,但不适用于HTML导出。使用现代CSS,浏览器可以为您进行编号(附加到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;
}

这样,您可以将纸张导出到LaTeX和HTML。


组织模式可以为所有部分编号,也可以没有。嗯,如何将媒体资源传递UNNUMBERED: t到标题?从ORG-NEWS:该属性UNNUMBERED为非零的标题现在不带节号而导出,无论其级别如何。该属性由孩子继承。
rasmus 2015年

@rasmus太棒了!但是,据我所知,这只是在组织模式8.3中引入的,尚未发布。
bastibe

它是在master中实现的,并且可在所有后端上使用。Org 8.3即将上线。它尚未发布意味着这是测试它并发布错误报告(必要时)的最佳时机!
拉斯姆斯2015年
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.