Reveal.jsスライドをreStructuredTextから作る。
Noboru Yamamoto
$Date: 2019/10/14 04:36:55 $
文書変換ツールpandocを用いて、 textベースでプレゼンテーションを 作成し、webベースで表示する方法を説明します。
Java script ライブラリreveal.jsを使用するので、 動的な表現も可能になっています。
pandocはフリーウェアとして公開されている高機能な文書変換プログラム
pandoc --list-input-formats
やpandoc --list-input-formats
でチェック.ここでは、reStructuredTextからHTML スライドショウに変換するのに必要なツールの インストールや実際の操作の流れを説明します。
pandocとreStructuredTextでreveal.jsのスライドを作成するには、最低、次のツールが必要です。
スライドの作成には、
の手順が必要です。
まずは、テキストエディタで次の内容を含むファイルを作成します。 名前をhabits.rstとします。
===============
ReSt to html
===============
:Author: 著者 (複数の場合はセミコロンで区切る)
:date: 2019.9.28
今日の予定
=============
朝にやること
-------------
起きる
++++++++
- アラームを止める
- ベッドから出る
朝ご飯
++++++++++++
- 卵を食べる
- コーヒーを飲む
昼にやること
-------------
昼ご飯
+++++++++++++
- 昼ごはんを食べる
- 昼寝をする
- おやつを食べる
夜にやること
-------------
夜ご飯
+++++++++++
- スパゲッティを食べる
- ワインを飲む
次のコマンドを使ってhabbits.rstをhabbit.htmlへ変換します。 指定したオプションについては、別途説明(pandocopts)します。
/usr/local/bin/pandoc -f rst -t revealjs --standalone \
--self-contained \
-V revealjs-url=file:<where/you/installed/reveal.js-master \
-V theme=sky \
-o habits.html habits.rst
作成されたhabits.htmlをwebブラウザで開く。
webブラウザ上のスライドショーで可能な操作。
カーソルキー | 上げ左右でスライド移動 |
スペース キー | 次のスライドへ |
ESCキー | スライド一覧 |
S | 発表者用ノートの表示 |
B | 一時的に画面を暗転/復帰 |
'Alt'+click | 画面のズーム/復帰 |
'ESC'キーを押すと、次のようなスライドの一覧が表示されます。
'Alt'+マウスクリックでクリックした場所を中心にスライドを拡大して表示します。
’s’キーを押すと、発表者用の画面が表示されます。 ブラウザのセキュリティ設定によっては、別ウィンドウを開く為の許可を求められます。 このあと、発表者画面が正常に表示されない場合には、発表者画面を一度閉じて、 ’s’キーをもう一度押してみてください。
この方法で作成したPDFファイルの例:
ここでは、reStructured Textの文書を作成するために必要となる要素の記述法を 説明します5。
========================================
reST To Reveal.js
========================================
:subtitle: reStructuredTextをpandocでReveal.jsスライドに
:Author: Noboru Yamamoto
:Date: 2019.10.03
レベル1のタイトル
=================
レベル2のタイトル
------------------
* item 1
* item 2
#. item 1
#. item 2
reveal.jsのフラグメント機能を使うことで、リストを一行ずつ表示します。 リストの行頭をインデントして始めることで、リストが逐次表示されます。
#. item 1
#. item 2
定義1
定義2
field body
second field body
*斜体* |
斜体 |
**太字** |
太字 |
``コードサンプル`` | コードサンプル |
reStructuredTextでは、テーブルを作成する複数の方法(シンプル、CSV、リスト、グリッド)があります。
A | B | A and B |
---|---|---|
False | False | False |
True | False | False |
False | True | False |
True | True | True |
===== ===== ========
A B A and B
===== ===== ========
False False False
True False False
False True False
True True True
===== ===== ========
A | B | A and B |
---|---|---|
False | False | False |
True | False | False |
False | True | False |
True | True | True |
.. csv-table:: CSV テーブル
:widths: "auto", "auto", "auto"
:header: A, B, "A and B"
False, False, False
True, False , False
False, True, False
True, True, True
A | B | A and B |
---|---|---|
False | False | False |
True | False | False |
False | True | False |
True | True | True |
.. list-table:: リスト テーブル
:widths: "auto", "auto", "auto"
:header-rows: 1
* - A
- B
- A and B
* - False
- False
- False
* - True
- False
- False
* - False
- True
- False
* - True
- True
- True
A | B | A and B |
---|---|---|
False | False | False |
True | False | False |
False | True | False |
True | True | True |
+-------+-------+-------------------+
|A |B |A and B |
+=======+=======+===================+
|False |False |False |
+-------+-------+-------------------+
|True |False |False |
+-------+-------+-------------------+
|False |True |False |
+-------+-------+-------------------+
|True |True |True |
+-------+-------+-------------------+
画像を挿入するのにも二つの方法があります。
まずは基本的な .. image:: ディレクティブを使った方法。
オプションとして、widthの他にも, height, scale, alt, align, targeteと言ったオプションが使えます。
figureディレクティブも使えます。
figureのレジェンド
figureのオプションには、imageのオプションに加えて figwidth, figclassが使えます。
言語を指定する事で、コードの色付けが自動で行われます。
.. code:: python
def hello():
print("Hello World!")
Viewerスクリーンに現れる発表者用ノートを作ります。
ブラウザで'S' キーを押して見て下さい。
.. note::
:class: notes
発表者用ノートをここに
- リストなどの
- ReST要素をいれることも可能
- キーsを押すと発表者用ノートが別ウィンドウで表示されます。
- \ `:class: notes`\ をお忘れなく。
数式(インライン)の入力例:
数式はインライン\ :math:`E=m c^2`\ でも
数式(ディスプレイモード)の入力例:
.. math::
\mathcal{S} = \int_{-\infty}^{\infty} d t m_0 \sqrt{1- \frac{\dot{x}^2}{c^2}}
htmlスライドを作成するのに必要となるpandocのオプションについて説明します。
-f, --from | 入力ファイルのフォーマット、reSTは rst で指定する。 |
-t, --to | 出力ファイルのフォーマット、reveal.jsは revealjs で指定する。 |
-o, --output | 出力先ファイルの指定。省略時は標準出力に出力。 |
-s, --standalone | 完結し、独立な出力ファイルを作成。 |
--self-contained | 外部依存を持たない、standaloneな出力ファイルを作成する。 |
--mathml | 数式をmathmlを使って出力する。(--mathjaxオプションもある。) |
HTMLスライドショー向けオプションの幾つか
--V <name>=<value> | メタ バリアブルズ <name>の値を <value> に設定する。 |
--base-header-level | 最上位のセクションのレベルを設定する。 |
--slide-level | スライドが始まるセクションレベルを指定。 |
HTMLスライドショーに使われる変数の幾つか (-V <var>=<value>の形式で指定する)。
revealjs-url | reveal.jsのjava scriptライブラリのある場所を指定する。 |
s5-usr, slidy-url, slideous-url | revealjs-urlのs5,slidy,slideous版 |
pandocはslide向けの出力形式として、reveal.js の他に、s5などのhtml スライドショー また、latex/beamerによるpdf出力をサポートしています。
同じreStructured Textによるスライド原稿から、適切なpandocのオプションを指定する事で、これらのスライドショーに 変換することもできます。
参考資料へのリンクなどを挙げておきます。
container ディレクティブによるfragment
compound ディレクティブによるfragment
Topic Title
Subsequent indented lines comprise the body of the topic, and are interpreted as body elements.
-o option
-a another option
a first definition
second definition
See <http://docutils.sf.net/docs/ref/rst/roles.html> for full info.
Role Name | Description |
---|---|
emphasis | Equivalent to emphasis |
literal | Equivalent to literal but processes backslash escapes |
math | Mathematical notation (input in LaTeX format) |
PEP | Reference to a numbered Python Enhancement Proposal |
RFC | Reference to a numbered Internet Request For Comments |
Role Name | Description |
---|---|
raw | For non-reST data; cannot be used directly (see docs) [0.3.6] |
strong | Equivalent to strong |
sub | Subscript |
sup | Superscript |
title | Title reference (book, etc.); standard default role |
See <http://docutils.sf.net/docs/ref/rst/directives.html> for full info.
Directive Name | Description (Docutils version added to, in [brackets]) |
---|---|
attention |
Specific admonition; also "caution", "danger", "error", "hint", "important", "note", "tip", "warning" |
admonition | Generic titled admonition: .. admonition:: By The Way |
rubric | .. rubric:: Informal Heading |
Directive Name | Description (Docutils version added to, in [brackets]) |
---|---|
image | .. image:: picture.png ; many options possible |
figure | Like "image", but with optional caption and legend |
sidebar | .. sidebar:: Title ; like a mini parallel document |
Directive Name | Description (Docutils version added to, in [brackets]) |
---|---|
parsed-literal | A literal block with parsed inline markup |
topic | .. topic:: Title ; like a mini section |
epigraph | Block quote with class="epigraph" |
highlights | Block quote with class="highlights" |
Directive Name | Description (Docutils version added to, in [brackets]) |
---|---|
pull-quote | Block quote with class="pull-quote" |
compound | Compound paragraphs [0.3.6] |
container | Generic block-level container element [0.3.10] |
Directive Name | Description (Docutils version added to, in [brackets]) |
---|---|
table | Create a titled table [0.3.1] |
list-table | Create a table from a uniform two-level bullet list [0.3.8] |
csv-table | Create a table from CSV data [0.3.4] |
Directive Name | Description (Docutils version added to, in [brackets]) |
---|---|
contents | Generate a table of contents |
sectnum | Automatically number sections, subsections, etc. |
header, footer | Create document decorations [0.3.8] |
Directive Name | Description (Docutils version added to, in [brackets]) |
---|---|
target-notes | Create an explicit footnote for each external target |
math | Mathematical notation (input in LaTeX format) |
meta | HTML-specific metadata |
Directive Name | Description (Docutils version added to, in [brackets]) |
---|---|
include | Read an external reST file as if it were inline |
raw | Non-reST data passed untouched to the Writer |
replace | Replacement text for substitution definitions |
class | Set a "class" attribute on the next element |
black
Directive Name | Description (Docutils version added to, in [brackets]) |
---|---|
role | Create a custom interpreted text role [0.3.2] |
default-role | Set the default interpreted text role [0.3.10] |
title | Set the metadata document title [0.3.10] |
sidebar title
sidebar contents
themeを変えて、beamer経由でpdfにすることも原理的には可能。↩︎
Windows, Macでは、バイナリパッケージをダウンロードして、インストーラーを起動す。↩︎
Linuxでは、apt,yumなどのツールでインストールすれば良いでしょう。 source codeからのインストールには、Haskellのコンパイラが必要です。↩︎
pandocで処理する際に, --revealjs-urlオプションで指定する。↩︎
pandocのmarkdownでは、セクションタイトルに対応するHTMLタグにアトリビュートを設定する方法が、 用意されています。しかし、pandocの受け付けるreStructuredTextにもこの機能はありません。 これがあればdata-background-imageなどの設定が可能となるのですが。↩︎