Template converter

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Template converter

joruib
Hello,

I'm again trying to develop my light Asciidoc to ConTeXt module. My aim is still the same: to write a novel in AsciiDoc and convert it to usable ConTeX for typesetting.

In previous questions I have asked here, we came to the conclusion that a template could be enough for this job and I want to try it, still I have found very little docs regarding this topic.

Where do I have to put my module? Which backend I use as a base? There is no backend which resembles TeX...

Any info on this, will be highly appreciated.

Thanks!
Reply | Threaded
Open this post in threaded view
|

Re: Template converter

gour
joruib wrote
write a novel in AsciiDoc and convert it to usable ConTeX for typesetting.
Recently (after seeing spec-initiative) I've decided to use AsciiDoc markup (over rst/markdown) for single source markup for all my writings - from small blog posts, articles and study notes up to the whole books as well as PDF presentations.

I'm glad to see people interested for ConTeXt typesetting - do you consider it is safe option (although, fortunately,  AsciiDoc provides other [more reliable] output formats like LaTeX)?

Any info on this, will be highly appreciated.
Please, share here if you manage to put something together and/or if there is some help one can provide although I do speak neither ConTeXt (yet) nor Ruby...tried several times with the former, but always gave up due to lack of time and docs to master it.

Btw, which editor you use for writing AsciiDoc/ConText markup?

Reply | Threaded
Open this post in threaded view
|

Re: Template converter

joruib
gour wrote
Recently (after seeing spec-initiative) I've decided to use AsciiDoc markup (over rst/markdown) for single source markup for all my writings - from small blog posts, articles and study notes up to the whole books as well as PDF presentations.
Same with me, that's why I want to learn more about its internals, specifically altering its output to suit me better.

gour wrote
I'm glad to see people interested for ConTeXt typesetting - do you consider it is safe option (although, fortunately,  AsciiDoc provides other [more reliable] output formats like LaTeX)?
Safe in which sense? ConTeXt is quite mature, I have typeset two novels already with it, it's just that I woul prefer to have my writing as uncluttered as possible and AsciiDoc seems a great choice.


Please, share here if you manage to put something together and/or if there is some help one can provide although I do speak neither ConTeXt (yet) nor Ruby...tried several times with the former, but always gave up due to lack of time and docs to master it.
ConTeXt is impressive, it is much more streamlined than LaTeX in my view. It was designed from the bottom up to have a common interface for everything. Coming from a LaTeX background, I had hard times in the beginning, to be honest and still use LaTeX when I need to prepare a manuscript in 'manuscript format' (courier, double spaced lines...) but my aim is to use ConTeXt for everything.

Btw, which editor you use for writing AsciiDoc/ConText markup?
Good old Notepad++ on Windows and Vim under Linux... I have been trying some distrancion free text apps such as FocusWriter and WriteMonkey... I tend to concentrate in the text.
Reply | Threaded
Open this post in threaded view
|

Re: Template converter

gour
This post was updated on .
On Thu, 24 Jan 2019 00:46:03 -0700 (MST)
"joruib [via Asciidoctor :: Discussion]"
<ml+s49171n6688h34@n6.nabble.com> wrote:

> Safe in which sense? ConTeXt is quite mature, I have typeset two
> novels already with it, it's just that I woul prefer to have my
> writing as uncluttered as possible and AsciiDoc seems a great choice.

Well, I'm thinking about the two or three points:

1. afaik, mostly Hans Hagen does work on it and, maybe, ConText has low 'bus
factor'

2. several times read about non-stability of the format in a sense that one is
not sure that old docs can still be typeset without some tweakings, while LaTeX
is much more stable in regard and

3. it's not easy to learn ConTeXt considering scattered docs or you can give
some hint?

> ConTeXt is impressive, it is much more streamlined than LaTeX in my
> view. It was designed from the bottom up to have a common interface
> for everything.

I fully agree!

> Coming from a LaTeX background,

I did prepare two books in the past by using LyX/LaTeX, but would like to
switch to ConTeXt for finaly typesetting.

> I had hard times in the beginning, to be honest and still use LaTeX when I
> need to prepare a manuscript in 'manuscript format' (courier, double spaced
> lines...) but my aim is to use ConTeXt for everything.

:-)

> Good old Notepad++ on Windows and Vim under Linux...

Are you happy-enough with Vim?

In the foreseeable future there is some studying ahead of me which means mostly
using editor to write Asciidoc...at the moment, I use Emacs, but just like a
noob user considering it maybe has better support for Asciidoc, but, otherwise,
I'm more happy with Vim which is also used as external editor for e.g. my mail
program...



attachment0 (849 bytes) <http://discuss.asciidoctor.org/attachment/6689/0/attachment0>
Reply | Threaded
Open this post in threaded view
|

Re: Template converter

mojavelinux
Administrator
In reply to this post by joruib
It's going to become much easier to make a custom converter in the upcoming Asciidoctor 2.0. Here's how you can create a converter from scratch:

Create the file context-converter.rb:

class ConTeXtConverter < Asciidoctor::Converter::Base
  register_for 'conTeXt'
  def initialize *args
    super
    basebackend 'tex'
    filetype 'tex'
    outfilesuffix '.tex'
  end

  def document node
    [node.title, node.content].join %(\n\n)
  end

  def paragraph node
    node.content
  end

  # etc...
end

To use it, set the backend to conTeXt and require your converter file when calling Asciidoctor:

 $ asciidoctor -b conTeXt -r ./context-converter.rb document.adoc

The result will be output to document.tex. What's left is the hard work of outputting all the correct markup ;)

The one thing to watch out for is that Asciidoctor assumes by default that the output is an SGML derivative. That means you'll need to replace SGML/XML character references with equivalent character references in tex. You should refer to the manpage converter (https://github.com/asciidoctor/asciidoctor/blob/master/lib/asciidoctor/converter/manpage.rb) for ideas about how to handle this (since it's a similar kind of markup language).

> There is no backend which resembles TeX...

In fact, there's a LaTeX converter for Asciidoctor available. You probably won't want to build on it since it has some rather complex features, but you can certainly use it as a reference. See https://github.com/asciidoctor/asciidoctor-latex/

I have no doubt there will be users who will find a ConTeXt converter useful. My advice is to find your niche and your audience and build a community with them. Then, publish the result to rubygems.org. If the converter reaches the point where anyone can use it, I'd be happy to invite you to host it in the asciidoctor organization. But get a prototype started first and we'll cross that bring in time.

Cheers,

-Dan

On Mon, Jan 21, 2019 at 5:24 AM joruib [via Asciidoctor :: Discussion] <[hidden email]> wrote:
Hello,

I'm again trying to develop my light Asciidoc to ConTeXt module. My aim is still the same: to write a novel in AsciiDoc and convert it to usable ConTeX for typesetting.

In previous questions I have asked here, we came to the conclusion that a template could be enough for this job and I want to try it, still I have found very little docs regarding this topic.

Where do I have to put my module? Which backend I use as a base? There is no backend which resembles TeX...

Any info on this, will be highly appreciated.

Thanks!


If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/Template-converter-tp6686.html
To start a new topic under Asciidoctor :: Discussion, email [hidden email]
To unsubscribe from Asciidoctor :: Discussion, click here.
NAML


--
Dan Allen | @mojavelinux | https://twitter.com/mojavelinux
Reply | Threaded
Open this post in threaded view
|

Re: Template converter

mojavelinux
Administrator
In reply to this post by joruib
If you want to support the use of templates with your converter, call the supports_templates directive.

class ConTeXtConverter < Asciidoctor::Converter::Base
  register_for 'conTeXt'
  def initialize *args
    super
    basebackend 'tex'
    filetype 'tex'
    outfilesuffix '.tex'
    supports_templates
  end

  # ...
end

Then you can feed additional templates that override the built-in handler methods:

 $ asciidoctor -b conTeXt -T templates -r ./context-converter.rb document.adoc

Templates can be written in any language supported by Tilt, though in the case of a non-SGML output format, ERB is your best bet.

I'd argue, however, that using templates to produce a TeX-based format is tricky. Templates lend themselves better to SGML-based output formats.

Cheers,

-Dan


On Fri, Feb 1, 2019 at 6:09 PM Dan Allen <[hidden email]> wrote:
It's going to become much easier to make a custom converter in the upcoming Asciidoctor 2.0. Here's how you can create a converter from scratch:

Create the file context-converter.rb:

class ConTeXtConverter < Asciidoctor::Converter::Base
  register_for 'conTeXt'
  def initialize *args
    super
    basebackend 'tex'
    filetype 'tex'
    outfilesuffix '.tex'
  end

  def document node
    [node.title, node.content].join %(\n\n)
  end

  def paragraph node
    node.content
  end

  # etc...
end

To use it, set the backend to conTeXt and require your converter file when calling Asciidoctor:

 $ asciidoctor -b conTeXt -r ./context-converter.rb document.adoc

The result will be output to document.tex. What's left is the hard work of outputting all the correct markup ;)

The one thing to watch out for is that Asciidoctor assumes by default that the output is an SGML derivative. That means you'll need to replace SGML/XML character references with equivalent character references in tex. You should refer to the manpage converter (https://github.com/asciidoctor/asciidoctor/blob/master/lib/asciidoctor/converter/manpage.rb) for ideas about how to handle this (since it's a similar kind of markup language).

> There is no backend which resembles TeX...

In fact, there's a LaTeX converter for Asciidoctor available. You probably won't want to build on it since it has some rather complex features, but you can certainly use it as a reference. See https://github.com/asciidoctor/asciidoctor-latex/

I have no doubt there will be users who will find a ConTeXt converter useful. My advice is to find your niche and your audience and build a community with them. Then, publish the result to rubygems.org. If the converter reaches the point where anyone can use it, I'd be happy to invite you to host it in the asciidoctor organization. But get a prototype started first and we'll cross that bring in time.

Cheers,

-Dan

On Mon, Jan 21, 2019 at 5:24 AM joruib [via Asciidoctor :: Discussion] <[hidden email]> wrote:
Hello,

I'm again trying to develop my light Asciidoc to ConTeXt module. My aim is still the same: to write a novel in AsciiDoc and convert it to usable ConTeX for typesetting.

In previous questions I have asked here, we came to the conclusion that a template could be enough for this job and I want to try it, still I have found very little docs regarding this topic.

Where do I have to put my module? Which backend I use as a base? There is no backend which resembles TeX...

Any info on this, will be highly appreciated.

Thanks!


If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/Template-converter-tp6686.html
To start a new topic under Asciidoctor :: Discussion, email [hidden email]
To unsubscribe from Asciidoctor :: Discussion, click here.
NAML


--
Dan Allen | @mojavelinux | https://twitter.com/mojavelinux


--
Dan Allen | @mojavelinux | https://twitter.com/mojavelinux
Reply | Threaded
Open this post in threaded view
|

Re: Template converter

joruib
I missed your two last posts! Have been busy these last two weeks... thanks a lot for pointing me in the right way.

The more I think about the converter, the more I see it as a real possibility... ConTeXt seems to be the more straightforward of the TeX dialects...