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

environments in ConTeXt? #2

Closed
ousia opened this issue Feb 5, 2015 · 2 comments
Closed

environments in ConTeXt? #2

ousia opened this issue Feb 5, 2015 · 2 comments

Comments

@ousia
Copy link

ousia commented Feb 5, 2015

Hi @bpj,

the simplest environment in ConTeXt is:

\start
my environment
\stop

But I guess you need something more complex.

Could you elaborate what you need from environments in ConTeXt? Please, include samples of those environments in LaTeX.

@bpj
Copy link
Owner

bpj commented Feb 7, 2015

Hi @ousia,

sorry for the delay. Real Life got a bit hectic the last two days.

My issue is not with translating LaTeX to ConTeXt per se, but with how I can modify pandoc-span2cmd.pl to support ConTeXt output.

I knew that ConTeXT uses \startSOMETHING...\stopSOMETHING but I wasn't sure how their magic worked. I see now that it mostly is up to the user to define each such environment. I guess it would work to either introduce a new special key, e.g. st=SOMETHING, and expand it to raw blocks \startSOMETHING/\stopSOMETHING at the beginning/end of the div, or to simply treat the old env=SOMETHING differently when the target format is ConTeXT.

However I also got confirmed what I seemed to remember that ConTeXT mostly uses square brackets for the arguments to \start, if any, but it seems that a mixture of square and curly brackets is possible too, and quite common with other commands too. so my treating curlies as the default in LaTeX for the purposes of automatic conversion of commands/environment names and arguments into HTML classes breaks down with ConTeXT. I guess there is a semantic difference to square/curly brackets which eludes me.

I have been thinking of extracting all arguments as classes or class fragments whose contents match the regular expression /[\{\[]([-_a-zA-Z0-9]+)[\]\}]/ even with LaTeX arguments, something like

no warnings 'uninitialized';
my($name, $args) = grep {length} split /\#/, $env_attr;
my $classes = $env_obj->attr->{class};
unless ( @$classes ) { # if no classes were already defined
    my @classy_args = $args =~ /[\{\[]([-_a-zA-Z0-9]+)[\]\}]/g;
    push @$classes, join '_', $name, @classy_args;
}

Then the only difference between filtering for LaTeX or ConTeXT output would be the sprintf formats used to produce the raw markup for the start/end of environments:

+{
    latex => {
        begin => '\\begin{%s}%s%s',
        end   => '\\end{%s}',
    }
    context => {
        begin => '\\start%s%s%s',
        end   => '\\stop%s',,
    }
}

so that you could write something like

<div env="foo#[bar-baz]{quux}">

and get, depending on output format:

\begin{foo}[bar-baz]{quux}

\startfoo[bar-baz]{quux}

<div class="foo_bar-baz_quux">

Naturally this is not meant to produce LaTeX and ConTeXT from the same source, but the filter could use the same routine for LaTeX and ConTeXT, apart from the sprintf formats.

Do you think that would work?

Also: is it safe to assume that the span body, as an argument to an ordinary ConTeXT command, ends up inside curly brackets?

@ousia
Copy link
Author

ousia commented Feb 8, 2015

@BjP, sorry for the delay.

I forgot to mention that I cannot code. Sorry, but your regular expression and the perl snippet are almost all Greek to me.

From your sample, I wonder whether this filtering makes sense with ConTeXt. I mean, ConTeXt can typeset from XML sources natively. As long as you have valid XHTML from pandoc, you don’t need to add an extra layer. I guess this is a much better method.

But as promised, I try to reply to your questions:

\begin{foo}[bar-baz]{quux}

I wonder whether the former is valid LaTeX.

\startfoo[bar-baz]{quux}

I would say this is not valid ConTeXt. At least {quiux} would be treated as text, not as part of the command.

Depending on the element, environments in ConTeXt use pairs of brackets. Most of them only one, but there are some environments with two, such as in:

\startitemize[a][left=(, right=), stopper=]

Braces in ConTeXt are used to group text modified by switches: mainly language and font switches. A sample that shows both:

{\sv på {\em svenska}}

This is different from LaTeX:

\foreignlanguage{swedish}{på \emph{svenska}}

Again, I wonder whether it is simply better to handle XHTML with ConTeXt natively.

I have a question about your sample.

One of the main benefits of markup languages (either XML-based, lightweight or even TeX-based) is the separation of layout from content. With the logical approach, text markup only needs classes (and identifiers, in some cases). Formatting itself is done later with CSS, or in the preamble of the document (in TeX).

I must be missing something, but when one has to define so complex attributes in the markdown source, I think (s)he is also making the task much harder than it should be. Mainly because it is mixing layout and content the bad way.

There are probably more than a couple of misunderstandings (if not plain mistakes) in my explanation. I don’t doubt that your filters serve important goals. Probably the LaTeX writer should be improved not to need those filters for basic features. Language switching is a basic feature when you write documents in other language than US English, because this is the default language in TeX. And also when you have multilingual documents, because in TeX hyphenation is enabled by default (svenska seems to be hyphenated svens-ka in Swedish [and in US English wrongly as sven-ska]).

And in my (mis?)understanding, it is really hard to handle a LaTeX document when the user cannot modify layout. I wonder whether it even makes sense. Because documents will always have the default layout. But again, I must be missing a lot of things.

Of course, don’t hesitate to ask whatever you need about ConTeXt. It might help that you include the most complex example you can think in both markdown and LaTeX.

BTW, for language tagging in markdown, there is an specific issue (jgm/pandoc/issues/895), but the people that need this feature don’t comment there. It is just to show the real demand that language tagging has in pandoc.

@bpj bpj closed this as completed Sep 23, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants