public inbox archive for pandoc-discuss@googlegroups.com
 help / color / mirror / Atom feed
* A filter to use linguex.sty for LaTeX numbered example lists
@ 2014-12-28 14:29 Thomas Hodgson
       [not found] ` <d801617b-98cd-4327-a94d-1c3d950a7f0e-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  0 siblings, 1 reply; 4+ messages in thread
From: Thomas Hodgson @ 2014-12-28 14:29 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw


[-- Attachment #1.1: Type: text/plain, Size: 1430 bytes --]

I have been wondering whether it would be possible to write a filter that 
would render numbered example lists in LaTeX output using a package such as 
linguex.sty <http://www.ctan.org/pkg/linguex>. I think I could write a 
filter that replaced OrderedLists marked as Examples with the right LaTeX 
output. (Although I haven't actually done it yet.) I'm not sure where to 
start on the question of cross references. In LaTeX I would put a `\label` 
command in the example and a `\ref` command to refer to it. When I look at 
the AST for a file with numbered examples I see that there is already the 
text of the required label e.g. (1), (2). So it doesn't look like there's 
anything that can be manipulated with a filter. If so, I don't think 
there's much point in going to the trouble of writing the first bit of the 
filter. Am I right in thinking that?

-- 
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/d801617b-98cd-4327-a94d-1c3d950a7f0e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

[-- Attachment #1.2: Type: text/html, Size: 1843 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: A filter to use linguex.sty for LaTeX numbered example lists
       [not found] ` <d801617b-98cd-4327-a94d-1c3d950a7f0e-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2014-12-29 20:07   ` John MacFarlane
       [not found]     ` <20141229200729.GC94320-qqGlgsTyhTiCiGiXOSDXzATffvOsOeKmqqGlgsTyhTjVYgS9aZXmwmsbx8vYGeVslXN7HHkbuXM@public.gmane.org>
  0 siblings, 1 reply; 4+ messages in thread
From: John MacFarlane @ 2014-12-29 20:07 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

Correct.  Example lists are converted to regular ordered lists in the
Markdown reader, so by the time you get a Pandoc structure, you can't
tell what was an example list and what was a regular list.

+++ Thomas Hodgson [Dec 28 14 06:29 ]:
>I have been wondering whether it would be possible to write a filter that
>would render numbered example lists in LaTeX output using a package such as
>linguex.sty <http://www.ctan.org/pkg/linguex>. I think I could write a
>filter that replaced OrderedLists marked as Examples with the right LaTeX
>output. (Although I haven't actually done it yet.) I'm not sure where to
>start on the question of cross references. In LaTeX I would put a `\label`
>command in the example and a `\ref` command to refer to it. When I look at
>the AST for a file with numbered examples I see that there is already the
>text of the required label e.g. (1), (2). So it doesn't look like there's
>anything that can be manipulated with a filter. If so, I don't think
>there's much point in going to the trouble of writing the first bit of the
>filter. Am I right in thinking that?
>
>-- 
>You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
>To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
>To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
>To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/d801617b-98cd-4327-a94d-1c3d950a7f0e%40googlegroups.com.
>For more options, visit https://groups.google.com/d/optout.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: A filter to use linguex.sty for LaTeX numbered example lists
       [not found]     ` <20141229200729.GC94320-qqGlgsTyhTiCiGiXOSDXzATffvOsOeKmqqGlgsTyhTjVYgS9aZXmwmsbx8vYGeVslXN7HHkbuXM@public.gmane.org>
@ 2014-12-29 22:56       ` Thomas Hodgson
       [not found]         ` <f4a2dc3e-de7f-4c26-96fa-68203976d624-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  0 siblings, 1 reply; 4+ messages in thread
From: Thomas Hodgson @ 2014-12-29 22:56 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw


[-- Attachment #1.1: Type: text/plain, Size: 2561 bytes --]

Thanks. I really like what Pandoc does. The only clear benefit I see from 
linguex.sty is links from the reference to the examples in created PDFs. 

On Monday, 29 December 2014 20:07:43 UTC, John MacFarlane wrote:
>
> Correct.  Example lists are converted to regular ordered lists in the 
> Markdown reader, so by the time you get a Pandoc structure, you can't 
> tell what was an example list and what was a regular list. 
>
> +++ Thomas Hodgson [Dec 28 14 06:29 ]: 
> >I have been wondering whether it would be possible to write a filter that 
> >would render numbered example lists in LaTeX output using a package such 
> as 
> >linguex.sty <http://www.ctan.org/pkg/linguex>. I think I could write a 
> >filter that replaced OrderedLists marked as Examples with the right LaTeX 
> >output. (Although I haven't actually done it yet.) I'm not sure where to 
> >start on the question of cross references. In LaTeX I would put a 
> `\label` 
> >command in the example and a `\ref` command to refer to it. When I look 
> at 
> >the AST for a file with numbered examples I see that there is already the 
> >text of the required label e.g. (1), (2). So it doesn't look like there's 
> >anything that can be manipulated with a filter. If so, I don't think 
> >there's much point in going to the trouble of writing the first bit of 
> the 
> >filter. Am I right in thinking that? 
> > 
> >-- 
> >You received this message because you are subscribed to the Google Groups 
> "pandoc-discuss" group. 
> >To unsubscribe from this group and stop receiving emails from it, send an 
> email to pandoc-discus...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org <javascript:>. 
> >To post to this group, send email to pandoc-...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org 
> <javascript:>. 
> >To view this discussion on the web visit 
> https://groups.google.com/d/msgid/pandoc-discuss/d801617b-98cd-4327-a94d-1c3d950a7f0e%40googlegroups.com. 
>
> >For more options, visit https://groups.google.com/d/optout. 
>
>

-- 
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/f4a2dc3e-de7f-4c26-96fa-68203976d624%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

[-- Attachment #1.2: Type: text/html, Size: 4557 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: A filter to use linguex.sty for LaTeX numbered example lists
       [not found]         ` <f4a2dc3e-de7f-4c26-96fa-68203976d624-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2015-01-18 19:34           ` Thomas Hodgson
  0 siblings, 0 replies; 4+ messages in thread
From: Thomas Hodgson @ 2015-01-18 19:34 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw


[-- Attachment #1.1: Type: text/plain, Size: 4702 bytes --]

I decided to play about with a Python script to replace numbered examples 
and references to them with LaTeX commands. Here's what I came up with:

```
#!/usr/bin/env python3

import argparse
import re
import sys

# Look at a file written in Pandoc-flavoured Markdown.
# See http://pandoc.org for details.
# Find numbered examples and replace with linguex.sty code.
# The result can be sent to Pandoc for conversion to PDF or LaTeX.


def replace_example(line):
    if re.match('\s{0,3}\(@[A-Za-z0-9-_]*\)', line):
        label = ''
        content = line[line.find(')')+1:-1].strip()
        if re.match('\s{0,3}\(@[A-Za-z0-9-_]+\)', line):
            label = line[line.find('@')+1:line.find(')')]
            labels.add(label)
        new_line = '\\ex.'
        if label:
            new_line += '\\label{{{}}}'.format(label)
        new_line += ' '
        new_line += content
        new_line += '\n'
        return new_line
    else:
        return line

if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument(
        'input',
        nargs='?',
        type=argparse.FileType('r'),
        default=sys.stdin
    )
    parser.add_argument(
        'output',
        nargs='?',
        type=argparse.FileType('w'),
        default=sys.stdout
    )
    args = parser.parse_args()
    lines = args.input.readlines()
    labels = set()
    lines = [replace_example(line) for line in lines]
    content = ''.join(lines)
    if labels:
        for label in labels:
            find = '(@{})'.format(label)
            replace = '\\ref{{{}}}'.format(label)
            content = content.replace(find, replace)
    args.output.write(content)
```

This can be used in e.g. `$ python3 examples.py Test.md | pandoc 
--standalone -V 'header-includes:\usepackage{linguex}' --output Test.tex` 
to get a PDF with the examples done with linguex. The advantage of this is 
that references to examples are now clickable links to those examples, and 
in some viewers show the example in a pop up preview.

On Monday, 29 December 2014 22:56:19 UTC, Thomas Hodgson wrote:
>
> Thanks. I really like what Pandoc does. The only clear benefit I see from 
> linguex.sty is links from the reference to the examples in created PDFs. 
>
> On Monday, 29 December 2014 20:07:43 UTC, John MacFarlane wrote:
>>
>> Correct.  Example lists are converted to regular ordered lists in the 
>> Markdown reader, so by the time you get a Pandoc structure, you can't 
>> tell what was an example list and what was a regular list. 
>>
>> +++ Thomas Hodgson [Dec 28 14 06:29 ]: 
>> >I have been wondering whether it would be possible to write a filter 
>> that 
>> >would render numbered example lists in LaTeX output using a package such 
>> as 
>> >linguex.sty <http://www.ctan.org/pkg/linguex>. I think I could write a 
>> >filter that replaced OrderedLists marked as Examples with the right 
>> LaTeX 
>> >output. (Although I haven't actually done it yet.) I'm not sure where to 
>> >start on the question of cross references. In LaTeX I would put a 
>> `\label` 
>> >command in the example and a `\ref` command to refer to it. When I look 
>> at 
>> >the AST for a file with numbered examples I see that there is already 
>> the 
>> >text of the required label e.g. (1), (2). So it doesn't look like 
>> there's 
>> >anything that can be manipulated with a filter. If so, I don't think 
>> >there's much point in going to the trouble of writing the first bit of 
>> the 
>> >filter. Am I right in thinking that? 
>> > 
>> >-- 
>> >You received this message because you are subscribed to the Google 
>> Groups "pandoc-discuss" group. 
>> >To unsubscribe from this group and stop receiving emails from it, send 
>> an email to pandoc-discus...-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org 
>> >To post to this group, send email to pandoc-...-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org 
>> >To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/pandoc-discuss/d801617b-98cd-4327-a94d-1c3d950a7f0e%40googlegroups.com. 
>>
>> >For more options, visit https://groups.google.com/d/optout. 
>>
>>

-- 
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/151ab3d0-e4cf-482c-87ec-3cec349c5342%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

[-- Attachment #1.2: Type: text/html, Size: 7849 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-01-18 19:34 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-12-28 14:29 A filter to use linguex.sty for LaTeX numbered example lists Thomas Hodgson
     [not found] ` <d801617b-98cd-4327-a94d-1c3d950a7f0e-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2014-12-29 20:07   ` John MacFarlane
     [not found]     ` <20141229200729.GC94320-qqGlgsTyhTiCiGiXOSDXzATffvOsOeKmqqGlgsTyhTjVYgS9aZXmwmsbx8vYGeVslXN7HHkbuXM@public.gmane.org>
2014-12-29 22:56       ` Thomas Hodgson
     [not found]         ` <f4a2dc3e-de7f-4c26-96fa-68203976d624-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2015-01-18 19:34           ` Thomas Hodgson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).