Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added: EnvironmentBlock < Extensions::BlockProcessor #7

Merged
merged 50 commits into from
Dec 22, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
34487db
- bug fix in node_processor, Block#open_process, handle case of nil …
Nov 8, 2014
657b728
First draft: [env.theorem]
Nov 8, 2014
3762bdc
Primitive toolchain: pre and post processor, block processor (env)
Nov 12, 2014
babe833
Added HTML handler for env, added ClickBlock class
Nov 17, 2014
67132de
Changed puts to warn and DEVELOPMENT to $VERBOSE
Nov 18, 2014
f0b9e8e
Added tests in ./tests. See the README there.
Nov 18, 2014
21473ea
Wired processors to converter, register some conditionally, add tests.
Nov 18, 2014
d979f54
ClickBlock is fully supported with hackish PrependProcessor.
Nov 19, 2014
ea7dcf7
Better css for both [env.foo] and [click.bar] elements via HTML handl…
Nov 20, 2014
3a3ac85
Started adding resources for cucumber tests
Nov 20, 2014
ab8627c
bup null
Nov 20, 2014
93c46fc
The construct [env.eq] now works in HTML.
Nov 20, 2014
a865685
The equation construct [env.eq] now works in HTML.
Nov 20, 2014
9210318
Change [env.eq] to [env.equation] (and save five lines of code:-)
Nov 21, 2014
e70338e
Change signal for numbering from * to %numbered, save more code:-)
Nov 21, 2014
f52f45c
Added directory try-out with contents for first users
Nov 21, 2014
18c5e01
Simplified the root README.adoc
Nov 21, 2014
3f56759
According context, puts \input MyEnviroment.tex or NewEnvironment.tex
Nov 21, 2014
24643db
Resoleve
Nov 21, 2014
7ee8c53
EnvironmentBlock now treats titles & numbering like ClickBlock
Nov 21, 2014
37e547c
Added rpec dir, one set of tests, and question for @mojavelinux.
Nov 21, 2014
235e1fe
Equation numbers now appear on right; vertical alignment so-so --
Nov 22, 2014
af60d6e
Fixed bug: generation of the file newEnvironments.tex
Nov 22, 2014
5c3bc2f
Better numbered equation style, many tweaks, improved docs
Nov 22, 2014
c7d252b
More and more specifc rspec tests for the TeX regex's -- see README
Nov 23, 2014
6c70f6e
Fixed bug in processing equations with option no-number
Dec 9, 2014
2c243b7
Added first draft of code that allows one to cross reference
Dec 9, 2014
7876810
Started setup for doctest
Dec 10, 2014
72f2c96
Added test cases to test/examples/adoc and test/examples/tex
Dec 10, 2014
53289d5
Changed task.rendere_opts arg to backend_name: :latex
Dec 10, 2014
daba8ec
Take into account inline_anchors of type link
Dec 10, 2014
a0fc1eb
Add .editorconfig
jirutka Nov 21, 2014
28fadd5
Clean trailing whitespaces and blank lines, insert final newline
jirutka Dec 13, 2014
d2c7c7b
Fix mismatched indentation in ruby sources
jirutka Dec 13, 2014
ab2ffd4
Fix some formatting
jirutka Nov 21, 2014
86c5b92
Fix Gemfile and gemspec
jirutka Nov 21, 2014
896d75e
Merge pull request #1 from jirutka/patch-2
Dec 13, 2014
ebc4f88
Fix bad class method definitions
jirutka Dec 13, 2014
f71a10d
Move colored_text to core_ext subdir and rename to colored_string
jirutka Dec 13, 2014
9b19f9c
Remove unnecessary monkey-patching of String
jirutka Nov 21, 2014
d07ef05
Remove unused String methods #eos and #whack
jirutka Dec 13, 2014
40b1c86
Fix camelCase method names
jirutka Dec 13, 2014
5fcc2fb
Remove unreasonable includes to main
jirutka Dec 13, 2014
c005ce2
Merge pull request #2 from jirutka/patch-3
Dec 15, 2014
e1081c2
Fix requires (avoid require_relative)
jirutka Dec 13, 2014
47bf4f7
Move all lib classes/modules under Asciidoctor::LaTeX namespace
jirutka Dec 13, 2014
12ff57a
Rename lib/asciidoctor-latex to lib/asciidoctor/latex
jirutka Dec 16, 2014
0614b4f
Add stem:latexmath to default options in bin/asciidoctor-latex
jirutka Dec 16, 2014
bd070ac
Fix instructions in readmes
jirutka Dec 16, 2014
192e7f0
Merge pull request #3 from jirutka/patch-4
Dec 18, 2014
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# top-most editorconfig file
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.{gemspec,rake,rb}]
indent_style = space
indent_size = 2

[{Gemfile,Rakefile}]
indent_style = space
indent_size = 2

[bin/**]
indent_style = space
indent_size = 2
30 changes: 29 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,33 @@
/_*/
*/_*/
/Gemfile.lock
/pkg/
/.ruby-gemset
/.ruby-version


samples/*.html
samples/*.tex
MYNOTES.adoc

# working directories jc
samples2
xx
work
tests/templates
tests/foo

# workng & test files
*.tex
*.pdf
*.aux
*.log
*.out
*.toc
*.html
tmp

ud.sh

LOG.adoc

try-out/possible/
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
source 'https://rubygems.org'
gemspec
256 changes: 89 additions & 167 deletions README.adoc
Original file line number Diff line number Diff line change
@@ -1,207 +1,129 @@
= AsciiDoc to LaTeX Converter for Asciidoctor
James Carlson
:numbered:
:toc:
:stem:
:toc2:
:stem:

== Purpose

The aim of the LaTeX converter, [path]_latex_converter.rb_, is to transform an AsciiDoc document containing mathematics into a LaTeX document.
Please see the file [path]_manual.adoc_ in this repository for a more details than presented here.
The aim of the LaTeX converter is to transform an AsciiDoc document containing
mathematical notation into a LaTeX document.
The converter also adds to Asciidoctor's facilities for handling mathematical
notation when rendered as HTML. Among these is the automatic numbering of theorems.
Please see the file [path]_manual.adoc_ in this repository for additional details
and for technical information.

The LaTeX converter supports two closely-related math formats, [blue]#AsciiMath# and [blue]#LaTeX#.
With the LaTeX converter, you can render expressions such as stem:[ a^2 + b^2 = c^2 ] and
For examples and a quick start guide, see <<Getting started>>.
Below, we describe the <<Document format,document formats>> used
for mathematics and the <<Command for rendering,commands>> for rendering a document into HTML or LaTeX.

[stem]
++++
e^{2\pi \sqrt{-1}} = 1
++++

within an AsciiDoc file.
== Installation

(The above won't render properly on GitHub right now, but will render if this README is run through Asciidoctor).
=== Using Rubygems

=== Asciimath syntax
_asciidoctor-latex has not been released yet_

AsciiMath syntax is as in
=== From repository

----
stem:[ a^2 + b^2 = c^2 ]
----

and

----
[stem]
++++
e^{2\pi \sqrt{-1}} = 1
++++
----

These are for inline and display math, respectively
The math content is written in LaTeX.
To activitate AsciiMath processing, set [blue]#+:stem:+# or [blue]#+:stem: latexmath+#.

=== LaTeX syntax

The syntax is standard LaTeX:

----
$ a^2 + b^2 = c^2 $
----

and

----
\[
e^{2\pi \sqrt{-1}} = 1
\]
----

== Usage

The command

$ asciidoctor -r ./latex_converter.rb -b latex test/sample1.adoc

will create a file [path]_test/sample1.tex_ from [path]_test/sample1.adoc_.
Then [path]_test/sample1.tex_ can be run through the +pdflatex+ command.
For a more complex example with a lot of math, see the file [path]_test/elliptic.adoc_ in this repo.
The HTML is rendered at http://epsilon.my.noteshare.io/notebook/195/?note=782[noteshare.io] for purposes of comparison.

== Files
If you'd like to install a development version from the repository, then use:

=== Code
$ git clone https://github.com/asciidoctor/asciidoctor-latex.git
$ cd asciidoctor-latex
$ gem build asciidoctor-latex.gemspec
$ gem install *.gem

* Ruby
latex_converter.rb:: the driver program to transform asciidoc files to tex files
node_processor.rb:: extends classes in the Asciidoctor module which translate AsciiDoc elements to TeX elements
tex_block.rb:: strips enclosing escaped braces as needed

* TeX
preamble.tex:: needed by latex_converter.rb to write a standara LaTeX preamble
asciidoc_macros.tex:: needed to carry out the translation of AsciiDoc blocks to LaTeX environments
macros.tex:: user macros
== Getting started

=== Test
The directory `try-out` contains a set of examples which
show what Asciidoctor LateX can do. Consult the `README` file
for directions on how to render an examples as
HTML or LaTeX. By comparing the source and rendered files,
you will quickly see how to write Asciidoc LaTeX.

manual.adoc:: describes which elments of Asciidoctor are translated into LaTeX
sample1.adoc:: math in conventonal LaTeX form, `$ ... $`, etc.
sample2.adoc:: like sample1, but the math is as in `stem:[a^ + b^2 = c^2]`, etc.
elliptic.adoc:: a complete example with lots of math
algebraic_varieties.ad:: a draft, very rough, but more like a real math article.

One should use all four files in testing the code.

== Coverage

=== AsciiDoc

The following constructs are among the those handled by the LaTeX converter at this time.
Please see [path]_manual.adoc_ for a complete list.

. Sections through level 5
. Numbered and un-numbered lists, including nested lists.
. Hyperlinks, e.g. `http://asciidoctor.org[Asciidoctor]`.
. Bold and italic text
. Hard break: line with trailing `+`
. Roles. Each role wich is translated into TeX require an entry in the `asciidoc_tex_macros` file.
For example, the role `[red]` [red]#which you see in use here# has the entry `\newcommand{\rolered}[1]{ \textcolor{red}{#1} }`.

=== LaTeX

A construct like the equation environment:
== Document format

Asciidoctor supports two closely-related math formats, [blue]#AsciiMath# and [blue]#LaTeX#.
For in-line mathematics, the first looks like `+++stem:[ a^2 + b^2 = c^2 ]+++`, while the
second looks like `$ a^2 + b^2 = c^2 $`. Both render as stem:[ a^2 + b^2 = c^2 ].
For displayed text, one can use
----
\[
\begin{equation}
...
\end{equation}
\]
[stem]
++++
e^{2\pi \sqrt{-1}} = 1
++++
----

needs to be transformed to ----

or
----
\begin{equation}
...
\end{equation}
\[
e^{2\pi \sqrt{-1}} = 1
\]
----
Both render as
\[
e^{2\pi \sqrt{-1}} = 1
\]
_Please note that the formulae above will not render properly
if you are reading it on GitHub. It will, however, render properly if you run
this file through Asciidoctor_.

////
There is a tricky point here.
Environments like the equation environment live outside of the delimiters `\[ ... \]`.
But others live inside.
Those that live outside in LaTeX must have their delimiters stripped.
The needed transformation is given by `TeXBlock.process_environments` in the file `tex_block.rb`.
////
== Commands for rendering

=== LaTeX Environments
Asciidoc math files can be rendered

The converter transforms open blocks into LaTeX environments.
Thus the source text:
. as HTML (the default)
. with the LaTeX converter additions such as automatic theorem numbering
. as LaTeX
+
*Note.* Forthcoming releases will make it possible to render
+
. as PDF
. as EPUB3 (Electronic book)

----
.Comment
[[foobar]]
--
This is merely a test.
--
----

is mapped to
=== HTML output

----
\begin{Comment}
\label{foobar}
This is merely a test.
\end{Comment}
----
To render a file into HTML, the Asciidoctor default,
use the usual `asciidoctor` command with this option:
```
$ asciidoctor -a stem foo.adoc
```
or with this
```
$ asciidoctor -a stem=latexmath foo.adoc
```
depending on the format.

If an identifier as in `[[foobar]]` is not specified, then a label is generated automatically, as in the example below:

----
.Comment
--
This is merely a test.
--
----

is mapped to

----
\begin{Comment}
\label{comment:13}
This is merely a test.
\end{Comment}
----

In this case the "13" means that this
was the 13th unlabeled comment.

The converter has little knowlege of LaTeX, so
it compiles a file of dumb definitions of environments
corresponding to the open blocks it encounters, e.g.,
=== LaTeX converter additions

----
\newtheorem{Comment}{Comment}
----
To employ the converter additions such as automatic theorem numbering, use
```
$ asciidoctor -r asciidoctor-latex -a stem=latexmath -b html foo.adoc
```
or
```
$ asciidoctor-latex -b html foo.adoc
```

These definitions are found in the file `new_environments.tex`.
The definition above has no necessary connection with theorem-proving, but it does provide an easy way to define a serviceable environment: "Comment" is in bold, and it is followed by an automatically generated number.
The body of the block is italicized.
The user will likely want to replace theses environment definitions better suited to the task at hand.

The TeXBlock package addresses the points made above in the case of both conventional LaTeX syntax and the `[stem]` block syntax.
=== LaTeX output

=== Issues
To render a file into LaTeX, use the `-r` (require rubygem) and `-b` (backend) option, e.g.:
```
$ asciidoctor -r asciidoctor-latex -a stem=latexmath -b latex foo.adoc
```
or simply with the wrapper script:
```
$ asciidoctor-latex foo.adoc
```

. The following symbols need to be passed through unchanged

** +--+
** +<+
** +>+
** +&+ -- important for typesettig matrices
** +...+ -- horizontal rule
== Switches

. Some apostrophes and quotes are bad -- they get translated as +&#1234;+ and TeX chokes on them.
Switch `:stem:` processing on by putthng the text `:stem:`
in your file. To turn the swtich on and set it to `latexmath`, say
instaed `stem:latexmth`.
Loading