public inbox archive for pandoc-discuss@googlegroups.com
 help / color / mirror / Atom feed
* How to render \textsf with pandoc.RawInline
@ 2022-02-09  5:20 Nandakumar Chandrasekhar
       [not found] ` <578d6310-8ebb-4154-b2b1-2614773829abn-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  0 siblings, 1 reply; 8+ messages in thread
From: Nandakumar Chandrasekhar @ 2022-02-09  5:20 UTC (permalink / raw)
  To: pandoc-discuss


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

Dear Folks,

I have the following text in my Markdown source:
========================
---
pagetitle: "sans-serif"
---
# Sans-Serif Lua

This is normal text. This is [sans-serif]{.sans-serif}
========================

I have written a Lua filter to convert the span [sans-serif]{.sans-serif} 
to Latex like so:
====================================
function Span(span)
if span.classes:includes "sans-serif" then
table.insert(span.content, 1, pandoc.RawInline('tex', '\\textsf '))
end
return span
end
====================================

Unfortunately the latex i get is {\textsf sans-serif} instead of 
\textsf{sans-serif}. Is there a way to get the output I want?

I could use sffamily inline but would like to learn how to get textsf to 
work.

Thanks in advance.

-- 
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 view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/578d6310-8ebb-4154-b2b1-2614773829abn%40googlegroups.com.

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

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

* Re: How to render \textsf with pandoc.RawInline
       [not found] ` <578d6310-8ebb-4154-b2b1-2614773829abn-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2022-02-09  7:57   ` Bastien DUMONT
  2022-02-09  9:18   ` Albert Krewinkel
  1 sibling, 0 replies; 8+ messages in thread
From: Bastien DUMONT @ 2022-02-09  7:57 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

Add the braces:

> table.insert(span.content, 1, pandoc.RawInline('tex', '\\textsf{'))
> table.insert(span.content, pandoc.RawInline('tex', '}'))

Le Tuesday 08 February 2022 à 09:20:46PM, Nandakumar Chandrasekhar a écrit :
> Dear Folks,
> 
> I have the following text in my Markdown source:
> ========================
> ---
> pagetitle: "sans-serif"
> ---
> # Sans-Serif Lua
> 
> This is normal text. This is [sans-serif]{.sans-serif}
> ========================
> 
> I have written a Lua filter to convert the span [sans-serif]{.sans-serif} to
> Latex like so:
> ====================================
> function Span(span)
> if span.classes:includes "sans-serif" then
> table.insert(span.content, 1, pandoc.RawInline('tex', '\\textsf '))
> end
> return span
> end
> ====================================
> 
> Unfortunately the latex i get is {\textsf sans-serif} instead of \textsf
> {sans-serif}. Is there a way to get the output I want?
> 
> I could use sffamily inline but would like to learn how to get textsf to work.
> 
> Thanks in advance.
> 
> 
> --
> 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 [1]pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> To view this discussion on the web visit [2]https://groups.google.com/d/msgid/
> pandoc-discuss/578d6310-8ebb-4154-b2b1-2614773829abn%40googlegroups.com.
> 
> References:
> 
> [1] mailto:pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
> [2] https://groups.google.com/d/msgid/pandoc-discuss/578d6310-8ebb-4154-b2b1-2614773829abn%40googlegroups.com?utm_medium=email&utm_source=footer

-- 
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 view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/YgNz28thVpcJ2jxR%40localhost.


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

* Re: How to render \textsf with pandoc.RawInline
       [not found] ` <578d6310-8ebb-4154-b2b1-2614773829abn-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  2022-02-09  7:57   ` Bastien DUMONT
@ 2022-02-09  9:18   ` Albert Krewinkel
       [not found]     ` <87h798bdgv.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
  1 sibling, 1 reply; 8+ messages in thread
From: Albert Krewinkel @ 2022-02-09  9:18 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw; +Cc: Nandakumar Chandrasekhar

Nandakumar Chandrasekhar <navanitachora-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes:

> Unfortunately the latex i get is {\textsf sans-serif} instead of
> \textsf{sans-serif}. Is there a way to get the output I want?
> I could use sffamily inline but would like to learn how to get textsf
> to work.

You could splice the raw TeX element in before the span and rely on the
LaTeX writer to add the braces around the span:

    function Span(span)
      if span.classes:includes "sans-serif" then
        return {
          pandoc.RawInline('tex', '\\textsf'),
          span
        }
      end
    end


-- 
Albert Krewinkel
GPG: 8eed e3e2 e8c5 6f18 81fe  e836 388d c0b2 1f63 1124


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

* Re: How to render \textsf with pandoc.RawInline
       [not found]     ` <87h798bdgv.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
@ 2022-02-09  9:56       ` Bastien DUMONT
  2022-02-09 10:35         ` Albert Krewinkel
  0 siblings, 1 reply; 8+ messages in thread
From: Bastien DUMONT @ 2022-02-09  9:56 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

I thought about this too, but can we be confident that the LaTeX writer will continue enclosing spans in braces in the future? I ask this because the ConTeXt writer doesn't do it, and there have been breaking changes in the LaTeX writer recently related to the shift from polyglossia to babel (e.g. changes in language tags).

Le Wednesday 09 February 2022 à 10:18:01AM, Albert Krewinkel a écrit :
> Nandakumar Chandrasekhar <navanitachora-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes:
> 
> > Unfortunately the latex i get is {\textsf sans-serif} instead of
> > \textsf{sans-serif}. Is there a way to get the output I want?
> > I could use sffamily inline but would like to learn how to get textsf
> > to work.
> 
> You could splice the raw TeX element in before the span and rely on the
> LaTeX writer to add the braces around the span:
> 
>     function Span(span)
>       if span.classes:includes "sans-serif" then
>         return {
>           pandoc.RawInline('tex', '\\textsf'),
>           span
>         }
>       end
>     end
> 
> 
> -- 
> Albert Krewinkel
> GPG: 8eed e3e2 e8c5 6f18 81fe  e836 388d c0b2 1f63 1124
> 
> -- 
> 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 view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/87h798bdgv.fsf%40zeitkraut.de.

-- 
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 view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/YgOP1SRSMlBW85Bk%40localhost.


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

* Re: How to render \textsf with pandoc.RawInline
  2022-02-09  9:56       ` Bastien DUMONT
@ 2022-02-09 10:35         ` Albert Krewinkel
       [not found]           ` <87czjwba0n.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
  0 siblings, 1 reply; 8+ messages in thread
From: Albert Krewinkel @ 2022-02-09 10:35 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw


Bastien DUMONT <bastien.dumont-VwIFZPTo/vqsTnJN9+BGXg@public.gmane.org> writes:

> Le Wednesday 09 February 2022 à 10:18:01AM, Albert Krewinkel a écrit :
>> Nandakumar Chandrasekhar <navanitachora-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes:
>> 
>> > Unfortunately the latex i get is {\textsf sans-serif} instead of
>> > \textsf{sans-serif}. Is there a way to get the output I want?
>> > I could use sffamily inline but would like to learn how to get textsf
>> > to work.
>> 
>> You could splice the raw TeX element in before the span and rely on the
>> LaTeX writer to add the braces around the span:

> I thought about this too, but can we be confident that the LaTeX
> writer will continue enclosing spans in braces in the future? I ask
> this because the ConTeXt writer doesn't do it, and there have been
> breaking changes in the LaTeX writer recently related to the shift
> from polyglossia to babel (e.g. changes in language tags).

Good question. I think it is *fairly* stable, but no way to predict the
future. Your's is definitely the more robust solution.

-- 
Albert Krewinkel
GPG: 8eed e3e2 e8c5 6f18 81fe  e836 388d c0b2 1f63 1124

-- 
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 view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/87czjwba0n.fsf%40zeitkraut.de.


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

* Re: How to render \textsf with pandoc.RawInline
       [not found]           ` <87czjwba0n.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
@ 2022-02-09 17:12             ` Nandakumar Chandrasekhar
       [not found]               ` <03dcdd40-1a09-4974-8ff3-80caedcaef16n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  2022-02-09 18:55             ` BPJ
  1 sibling, 1 reply; 8+ messages in thread
From: Nandakumar Chandrasekhar @ 2022-02-09 17:12 UTC (permalink / raw)
  To: pandoc-discuss


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

Thank you both for your input. I used the code suggested by @Bastien Dumont 
and it works like a charm.

I do have one question about the format parameter being 'tex' rather than 
'latex'.

Does it matter which is used since they both seem to work? I am asking 
simply because the writer name is latex and just wanted to know if using 
'tex' is a convention.

Many thanks.

On Wednesday, February 9, 2022 at 4:08:12 PM UTC+5:30 Albert Krewinkel 
wrote:

>
> Bastien DUMONT <bastien...-VwIFZPTo/vqsTnJN9+BGXg@public.gmane.org> writes:
>
> > Le Wednesday 09 February 2022 à 10:18:01AM, Albert Krewinkel a écrit :
> >> Nandakumar Chandrasekhar <navani...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes:
> >> 
> >> > Unfortunately the latex i get is {\textsf sans-serif} instead of
> >> > \textsf{sans-serif}. Is there a way to get the output I want?
> >> > I could use sffamily inline but would like to learn how to get textsf
> >> > to work.
> >> 
> >> You could splice the raw TeX element in before the span and rely on the
> >> LaTeX writer to add the braces around the span:
>
> > I thought about this too, but can we be confident that the LaTeX
> > writer will continue enclosing spans in braces in the future? I ask
> > this because the ConTeXt writer doesn't do it, and there have been
> > breaking changes in the LaTeX writer recently related to the shift
> > from polyglossia to babel (e.g. changes in language tags).
>
> Good question. I think it is *fairly* stable, but no way to predict the
> future. Your's is definitely the more robust solution.
>
> -- 
> Albert Krewinkel
> GPG: 8eed e3e2 e8c5 6f18 81fe e836 388d c0b2 1f63 1124
>

-- 
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 view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/03dcdd40-1a09-4974-8ff3-80caedcaef16n%40googlegroups.com.

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

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

* Re: How to render \textsf with pandoc.RawInline
       [not found]               ` <03dcdd40-1a09-4974-8ff3-80caedcaef16n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2022-02-09 18:05                 ` Bastien DUMONT
  0 siblings, 0 replies; 8+ messages in thread
From: Bastien DUMONT @ 2022-02-09 18:05 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

As long as LaTeX is the only TeX format you use, it doesn't make any difference. The problem will arise if you also convert to ConTeXt, since your LaTeX snippets would be also passed to ConTeXt, which would result in an undefined control sequence error. In my eyes, 'tex' format should be used only with portable TeX code.

Le Wednesday 09 February 2022 à 09:12:36AM, Nandakumar Chandrasekhar a écrit :
> Thank you both for your input. I used the code suggested by @Bastien Dumont and
> it works like a charm.
> 
> I do have one question about the format parameter being 'tex' rather than
> 'latex'.
> 
> Does it matter which is used since they both seem to work? I am asking simply
> because the writer name is latex and just wanted to know if using 'tex' is a
> convention.
> 
> Many thanks.
> 
> On Wednesday, February 9, 2022 at 4:08:12 PM UTC+5:30 Albert Krewinkel wrote:
> 
> 
>     Bastien DUMONT <bastien...-VwIFZPTo/vqsTnJN9+BGXg@public.gmane.org> writes:
> 
>     > Le Wednesday 09 February 2022 à 10:18:01AM, Albert Krewinkel a écrit :
>     >> Nandakumar Chandrasekhar <navani...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes:
>     >>
>     >> > Unfortunately the latex i get is {\textsf sans-serif} instead of
>     >> > \textsf{sans-serif}. Is there a way to get the output I want?
>     >> > I could use sffamily inline but would like to learn how to get textsf
>     >> > to work.
>     >>
>     >> You could splice the raw TeX element in before the span and rely on the
>     >> LaTeX writer to add the braces around the span:
> 
>     > I thought about this too, but can we be confident that the LaTeX
>     > writer will continue enclosing spans in braces in the future? I ask
>     > this because the ConTeXt writer doesn't do it, and there have been
>     > breaking changes in the LaTeX writer recently related to the shift
>     > from polyglossia to babel (e.g. changes in language tags).
> 
>     Good question. I think it is *fairly* stable, but no way to predict the
>     future. Your's is definitely the more robust solution.
> 
>     --
>     Albert Krewinkel
>     GPG: 8eed e3e2 e8c5 6f18 81fe e836 388d c0b2 1f63 1124
> 
> --
> 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 [1]pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> To view this discussion on the web visit [2]https://groups.google.com/d/msgid/
> pandoc-discuss/03dcdd40-1a09-4974-8ff3-80caedcaef16n%40googlegroups.com.
> 
> References:
> 
> [1] mailto:pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
> [2] https://groups.google.com/d/msgid/pandoc-discuss/03dcdd40-1a09-4974-8ff3-80caedcaef16n%40googlegroups.com?utm_medium=email&utm_source=footer

-- 
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 view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/YgQChvZu8GxEykPs%40localhost.


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

* Re: How to render \textsf with pandoc.RawInline
       [not found]           ` <87czjwba0n.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
  2022-02-09 17:12             ` Nandakumar Chandrasekhar
@ 2022-02-09 18:55             ` BPJ
  1 sibling, 0 replies; 8+ messages in thread
From: BPJ @ 2022-02-09 18:55 UTC (permalink / raw)
  To: pandoc-discuss

[-- Attachment #1: Type: text/plain, Size: 2440 bytes --]

An extra pair of braces around the argument doesn't hurt, so you can 
splice in `pandoc.RawInline('latex', '\\textsf{')` before the span and 
`pandoc.RawInline('latex', '}')` after the span.

FWIW I attach something I had lying around, with some custom commands 
removed.

Den ons 9 feb. 2022 11:38Albert Krewinkel <albert+pandoc-9EawChwDxG8hFhg+JK9F0w@public.gmane.org> 
skrev:

>
> Bastien DUMONT <bastien.dumont-VwIFZPTo/vqsTnJN9+BGXg@public.gmane.org> writes:
>
> > Le Wednesday 09 February 2022 à 10:18:01AM, Albert Krewinkel a écrit :
> >> Nandakumar Chandrasekhar <navanitachora-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes:
> >> 
> >> > Unfortunately the latex i get is {\textsf sans-serif} instead of
> >> > \textsf{sans-serif}. Is there a way to get the output I want?
> >> > I could use sffamily inline but would like to learn how to get textsf
> >> > to work.
> >> 
> >> You could splice the raw TeX element in before the span and rely on the
> >> LaTeX writer to add the braces around the span:
>
> > I thought about this too, but can we be confident that the LaTeX
> > writer will continue enclosing spans in braces in the future? I ask
> > this because the ConTeXt writer doesn't do it, and there have been
> > breaking changes in the LaTeX writer recently related to the shift
> > from polyglossia to babel (e.g. changes in language tags).
>
> Good question. I think it is *fairly* stable, but no way to predict the
> future. Your's is definitely the more robust solution.
>
> -- 
> Albert Krewinkel
> GPG: 8eed e3e2 e8c5 6f18 81fe  e836 388d c0b2 1f63 1124
>
> -- 
> 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 view this discussion on the web visit 
> https://groups.google.com/d/msgid/pandoc-discuss/87czjwba0n.fsf%40zeitkraut.de
> .
>

-- 
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 view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/da2f8298-6c48-43f8-3463-db8c25bf2851%40gmail.com.

[-- Attachment #2: latex-inject.lua --]
[-- Type: text/x-lua, Size: 1092 bytes --]

-- Pandoc filter which injects LaTeX markup for sans or small caps font around
-- divs, spans and links with a class 'sf' or 'sc'

local code_for = {
  Span = {
    sf = '\\textsf{',
    sc = '\\textsc{',
  },
  Div = {
    sf = '\\begin{sffamily}',
    sc = '\\begin{scshape}',
  },
}

local post_for = {
  Span = pandoc.RawInline('latex', '}'),
}

local raw_for = {
  Span = pandoc.RawInline,
  Div = pandoc.RawBlock,
}

local elem_for = {}

for tag, codes in pairs(code_for) do
  Raw = raw_for[tag]
  for_tag = {}
  for class, code in pairs(codes) do
    for_class = {}
    for_class.pre = Raw('latex', code)
    for_class.post = post_for[tag] or Raw('latex', code:gsub('begin','end'))
    for_tag[class] = for_class
  end
  elem_for[tag] = for_tag
end

elem_for.Link = elem_for.Span

local function inject (elem)
  for_tag = elem_for[elem.tag]
  for class, raw in pairs(for_tag) do
    if elem.classes:includes(class) then
      return { raw.pre, elem, raw.post }
    end
  end
  return nil
end

local filter = {}
for tag in pairs(elem_for) do
  filter[tag] = inject
end

return {filter}

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

end of thread, other threads:[~2022-02-09 18:55 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-09  5:20 How to render \textsf with pandoc.RawInline Nandakumar Chandrasekhar
     [not found] ` <578d6310-8ebb-4154-b2b1-2614773829abn-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2022-02-09  7:57   ` Bastien DUMONT
2022-02-09  9:18   ` Albert Krewinkel
     [not found]     ` <87h798bdgv.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
2022-02-09  9:56       ` Bastien DUMONT
2022-02-09 10:35         ` Albert Krewinkel
     [not found]           ` <87czjwba0n.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
2022-02-09 17:12             ` Nandakumar Chandrasekhar
     [not found]               ` <03dcdd40-1a09-4974-8ff3-80caedcaef16n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2022-02-09 18:05                 ` Bastien DUMONT
2022-02-09 18:55             ` BPJ

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).