* Lua Filter for \citeauthor and \citetitle in HTML
@ 2023-01-28 22:07 Bernardo C. D. A. Vasconcelos
[not found] ` <51e71797-b029-4438-be64-6a8a15dd500an-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
0 siblings, 1 reply; 9+ messages in thread
From: Bernardo C. D. A. Vasconcelos @ 2023-01-28 22:07 UTC (permalink / raw)
To: pandoc-discuss
[-- Attachment #1.1: Type: text/plain, Size: 1148 bytes --]
An HTML equivalent of these commands was proposed in Github, but there was
no feasible way for it to be implemented as part of Citeproc. I suggested a
Lua filter to achieve this and John said it sounded doable.
I learned some Lua and experimented, but I didn't come close enough to have
something worth sharing. In short: I imagined something like
`[@Ref]{.citetitle}` and `[@Ref]{.citeauthor}`. So this would imply:
parsing the bib data and saving it to a Lua table (stuck here); filtering
spans; checking the type and performing the replacement (not clear to me
either what the correct way would be to replace the id with the data or if
this would have to run before/after citeproc).
Any pointers would be much appreciated.
--
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/51e71797-b029-4438-be64-6a8a15dd500an%40googlegroups.com.
[-- Attachment #1.2: Type: text/html, Size: 1478 bytes --]
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Lua Filter for \citeauthor and \citetitle in HTML
[not found] ` <51e71797-b029-4438-be64-6a8a15dd500an-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2023-01-28 22:35 ` Bastien DUMONT
2023-01-30 16:49 ` Bernardo C. D. A. Vasconcelos
0 siblings, 1 reply; 9+ messages in thread
From: Bastien DUMONT @ 2023-01-28 22:35 UTC (permalink / raw)
To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw
I think that it would be better to run it before citeproc, since you don't want citeproc output (unless you want to still benefit from the "ibid./cited" feature). Citeproc would not help you so much here because it does not tag the different parts of a formatted citation. On the other hand, parsing the bib file would be rather simple if it is in the CSL JSON format: then you would just have to use one of the JSON modules for Lua to import your bibliographic references into a Lua table. If you use Bib(La)TeX, you can convert a .bib file to a .json with `pandoc -f bibtex (or biblatex) -t csljson myfile.bib -o myfile.json`.
Le Saturday 28 January 2023 à 02:07:54PM, Bernardo C. D. A. Vasconcelos a écrit :
> An HTML equivalent of these commands was proposed in Github, but there was no
> feasible way for it to be implemented as part of Citeproc. I suggested a Lua
> filter to achieve this and John said it sounded doable.
>
> I learned some Lua and experimented, but I didn't come close enough to have
> something worth sharing. In short: I imagined something like `[@Ref]
> {.citetitle}` and `[@Ref]{.citeauthor}`. So this would imply: parsing the bib
> data and saving it to a Lua table (stuck here); filtering spans; checking the
> type and performing the replacement (not clear to me either what the correct
> way would be to replace the id with the data or if this would have to run
> before/after citeproc).
>
> Any pointers would be much appreciated.
>
> --
> 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/51e71797-b029-4438-be64-6a8a15dd500an%40googlegroups.com.
>
> References:
>
> [1] mailto:pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
> [2] https://groups.google.com/d/msgid/pandoc-discuss/51e71797-b029-4438-be64-6a8a15dd500an%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/Y9WjLKlot5OuSwhp%40localhost.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Lua Filter for \citeauthor and \citetitle in HTML
2023-01-28 22:35 ` Bastien DUMONT
@ 2023-01-30 16:49 ` Bernardo C. D. A. Vasconcelos
[not found] ` <4865a325-42c0-4245-b992-b4fbdeab576en-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
0 siblings, 1 reply; 9+ messages in thread
From: Bernardo C. D. A. Vasconcelos @ 2023-01-30 16:49 UTC (permalink / raw)
To: pandoc-discuss
[-- Attachment #1.1: Type: text/plain, Size: 2954 bytes --]
Thanks for the feedback, Bastien!
Can you think of a similar example script that contains the function to
parse the bib data? I searched for it online to no avail.
On Saturday, January 28, 2023 at 7:35:40 PM UTC-3 Bastien Dumont wrote:
> I think that it would be better to run it before citeproc, since you don't
> want citeproc output (unless you want to still benefit from the
> "ibid./cited" feature). Citeproc would not help you so much here because it
> does not tag the different parts of a formatted citation. On the other
> hand, parsing the bib file would be rather simple if it is in the CSL JSON
> format: then you would just have to use one of the JSON modules for Lua to
> import your bibliographic references into a Lua table. If you use
> Bib(La)TeX, you can convert a .bib file to a .json with `pandoc -f bibtex
> (or biblatex) -t csljson myfile.bib -o myfile.json`.
>
> Le Saturday 28 January 2023 à 02:07:54PM, Bernardo C. D. A. Vasconcelos a
> écrit :
> > An HTML equivalent of these commands was proposed in Github, but there
> was no
> > feasible way for it to be implemented as part of Citeproc. I suggested a
> Lua
> > filter to achieve this and John said it sounded doable.
> >
> > I learned some Lua and experimented, but I didn't come close enough to
> have
> > something worth sharing. In short: I imagined something like `[@Ref]
> > {.citetitle}` and `[@Ref]{.citeauthor}`. So this would imply: parsing
> the bib
> > data and saving it to a Lua table (stuck here); filtering spans;
> checking the
> > type and performing the replacement (not clear to me either what the
> correct
> > way would be to replace the id with the data or if this would have to run
> > before/after citeproc).
> >
> > Any pointers would be much appreciated.
> >
> > --
> > 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-discus...-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> > To view this discussion on the web visit [2]
> https://groups.google.com/d/msgid/
> > pandoc-discuss/51e71797-b029-4438-be64-6a8a15dd500an%40googlegroups.com.
> >
> > References:
> >
> > [1] mailto:pandoc-discus...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
> > [2]
> https://groups.google.com/d/msgid/pandoc-discuss/51e71797-b029-4438-be64-6a8a15dd500an%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/4865a325-42c0-4245-b992-b4fbdeab576en%40googlegroups.com.
[-- Attachment #1.2: Type: text/html, Size: 4575 bytes --]
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Lua Filter for \citeauthor and \citetitle in HTML
[not found] ` <4865a325-42c0-4245-b992-b4fbdeab576en-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2023-01-30 17:21 ` Bastien DUMONT
2023-01-30 17:41 ` John MacFarlane
0 siblings, 1 reply; 9+ messages in thread
From: Bastien DUMONT @ 2023-01-30 17:21 UTC (permalink / raw)
To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw
Do you mean a function that parses the .bib file directly? I really think that it would be easier to convert the .bib file to a CSL JSON file and import it via a JSON parser.
Le Monday 30 January 2023 à 08:49:36AM, Bernardo C. D. A. Vasconcelos a écrit :
> Thanks for the feedback, Bastien!
> Can you think of a similar example script that contains the function to parse
> the bib data? I searched for it online to no avail.
> On Saturday, January 28, 2023 at 7:35:40 PM UTC-3 Bastien Dumont wrote:
>
> I think that it would be better to run it before citeproc, since you don't
> want citeproc output (unless you want to still benefit from the "ibid./
> cited" feature). Citeproc would not help you so much here because it does
> not tag the different parts of a formatted citation. On the other hand,
> parsing the bib file would be rather simple if it is in the CSL JSON
> format: then you would just have to use one of the JSON modules for Lua to
> import your bibliographic references into a Lua table. If you use Bib(La)
> TeX, you can convert a .bib file to a .json with `pandoc -f bibtex (or
> biblatex) -t csljson myfile.bib -o myfile.json`.
>
> Le Saturday 28 January 2023 à 02:07:54PM, Bernardo C. D. A. Vasconcelos a
> écrit :
> > An HTML equivalent of these commands was proposed in Github, but there
> was no
> > feasible way for it to be implemented as part of Citeproc. I suggested a
> Lua
> > filter to achieve this and John said it sounded doable.
> >
> > I learned some Lua and experimented, but I didn't come close enough to
> have
> > something worth sharing. In short: I imagined something like `[@Ref]
> > {.citetitle}` and `[@Ref]{.citeauthor}`. So this would imply: parsing the
> bib
> > data and saving it to a Lua table (stuck here); filtering spans; checking
> the
> > type and performing the replacement (not clear to me either what the
> correct
> > way would be to replace the id with the data or if this would have to run
> > before/after citeproc).
> >
> > Any pointers would be much appreciated.
> >
> > --
> > 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-discus...-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> > To view this discussion on the web visit [2][1]https://groups.google.com/
> d/msgid/
> > pandoc-discuss/51e71797-b029-4438-be64-6a8a15dd500an%[2]
> 40googlegroups.com.
> >
> > References:
> >
> > [1] mailto:pandoc-discus...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
> > [2] [3]https://groups.google.com/d/msgid/pandoc-discuss/
> 51e71797-b029-4438-be64-6a8a15dd500an%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 [4]pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> To view this discussion on the web visit [5]https://groups.google.com/d/msgid/
> pandoc-discuss/4865a325-42c0-4245-b992-b4fbdeab576en%40googlegroups.com.
>
> References:
>
> [1] https://groups.google.com/d/msgid/
> [2] http://40googlegroups.com/
> [3] https://groups.google.com/d/msgid/pandoc-discuss/51e71797-b029-4438-be64-6a8a15dd500an%40googlegroups.com?utm_medium=email&utm_source=footer
> [4] mailto:pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
> [5] https://groups.google.com/d/msgid/pandoc-discuss/4865a325-42c0-4245-b992-b4fbdeab576en%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/Y9f8i/Jl%2BgDjNo/a%40localhost.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Lua Filter for \citeauthor and \citetitle in HTML
2023-01-30 17:21 ` Bastien DUMONT
@ 2023-01-30 17:41 ` John MacFarlane
[not found] ` <9786B5A5-9022-4E5B-85DE-39D4A2CAFD8F-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
0 siblings, 1 reply; 9+ messages in thread
From: John MacFarlane @ 2023-01-30 17:41 UTC (permalink / raw)
To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw
In a Lua filter you could probably just use pandoc.read with the format "bibtex" or "biblatex".
> On Jan 30, 2023, at 9:21 AM, Bastien DUMONT <bastien.dumont-VwIFZPTo/vqsTnJN9+BGXg@public.gmane.org> wrote:
>
> Do you mean a function that parses the .bib file directly? I really think that it would be easier to convert the .bib file to a CSL JSON file and import it via a JSON parser.
>
> Le Monday 30 January 2023 à 08:49:36AM, Bernardo C. D. A. Vasconcelos a écrit :
>> Thanks for the feedback, Bastien!
>> Can you think of a similar example script that contains the function to parse
>> the bib data? I searched for it online to no avail.
>> On Saturday, January 28, 2023 at 7:35:40 PM UTC-3 Bastien Dumont wrote:
>>
>> I think that it would be better to run it before citeproc, since you don't
>> want citeproc output (unless you want to still benefit from the "ibid./
>> cited" feature). Citeproc would not help you so much here because it does
>> not tag the different parts of a formatted citation. On the other hand,
>> parsing the bib file would be rather simple if it is in the CSL JSON
>> format: then you would just have to use one of the JSON modules for Lua to
>> import your bibliographic references into a Lua table. If you use Bib(La)
>> TeX, you can convert a .bib file to a .json with `pandoc -f bibtex (or
>> biblatex) -t csljson myfile.bib -o myfile.json`.
>>
>> Le Saturday 28 January 2023 à 02:07:54PM, Bernardo C. D. A. Vasconcelos a
>> écrit :
>>> An HTML equivalent of these commands was proposed in Github, but there
>> was no
>>> feasible way for it to be implemented as part of Citeproc. I suggested a
>> Lua
>>> filter to achieve this and John said it sounded doable.
>>>
>>> I learned some Lua and experimented, but I didn't come close enough to
>> have
>>> something worth sharing. In short: I imagined something like `[@Ref]
>>> {.citetitle}` and `[@Ref]{.citeauthor}`. So this would imply: parsing the
>> bib
>>> data and saving it to a Lua table (stuck here); filtering spans; checking
>> the
>>> type and performing the replacement (not clear to me either what the
>> correct
>>> way would be to replace the id with the data or if this would have to run
>>> before/after citeproc).
>>>
>>> Any pointers would be much appreciated.
>>>
>>> --
>>> 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-discus...-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
>>> To view this discussion on the web visit [2][1]https://groups.google.com/
>> d/msgid/
>>> pandoc-discuss/51e71797-b029-4438-be64-6a8a15dd500an%[2]
>> 40googlegroups.com.
>>>
>>> References:
>>>
>>> [1] mailto:pandoc-discus...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
>>> [2] [3]https://groups.google.com/d/msgid/pandoc-discuss/
>> 51e71797-b029-4438-be64-6a8a15dd500an%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 [4]pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
>> To view this discussion on the web visit [5]https://groups.google.com/d/msgid/
>> pandoc-discuss/4865a325-42c0-4245-b992-b4fbdeab576en%40googlegroups.com.
>>
>> References:
>>
>> [1] https://groups.google.com/d/msgid/
>> [2] http://40googlegroups.com/
>> [3] https://groups.google.com/d/msgid/pandoc-discuss/51e71797-b029-4438-be64-6a8a15dd500an%40googlegroups.com?utm_medium=email&utm_source=footer
>> [4] mailto:pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
>> [5] https://groups.google.com/d/msgid/pandoc-discuss/4865a325-42c0-4245-b992-b4fbdeab576en%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/Y9f8i/Jl%2BgDjNo/a%40localhost.
--
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/9786B5A5-9022-4E5B-85DE-39D4A2CAFD8F%40gmail.com.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Lua Filter for \citeauthor and \citetitle in HTML
[not found] ` <9786B5A5-9022-4E5B-85DE-39D4A2CAFD8F-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2023-03-08 14:00 ` Bernardo C. D. A. Vasconcelos
[not found] ` <4641cd0b-adb7-408f-b025-f56a0b293be5n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
0 siblings, 1 reply; 9+ messages in thread
From: Bernardo C. D. A. Vasconcelos @ 2023-03-08 14:00 UTC (permalink / raw)
To: pandoc-discuss
[-- Attachment #1.1: Type: text/plain, Size: 8295 bytes --]
A filter that seems close enough is the bibexport filter at
https://raw.githubusercontent.com/pandoc/lua-filters/master/bibexport/bibexport.lua
which I reproduce below:
```
local utils = require 'pandoc.utils'
local List = require 'pandoc.List'
local citation_id_set = {}
local type = utils.type or type
-- Collect all citation IDs.
function Cite (c)
local cs = c.citations
for i = 1, #cs do
citation_id_set[cs[i].id or cs[i].citationId] = true
end
end
--- Return a list of citation IDs
function citation_ids ()
local citations = {};
for cid, _ in pairs(citation_id_set) do
citations[#citations + 1] = cid
end
return citations
end
--- stringify meta inline elements. Pandoc prior to version 2.8
-- didn't properly tag MetaInline values, so making it necessary to use an
-- auxiliary Span.
local stringifyMetaInlines = function (el)
return el.t
and utils.stringify(el)
or utils.stringify(pandoc.Span(el))
end
function bibdata (bibliography)
function bibname (bibitem)
return type(bibitem) == 'string'
and bibitem:gsub('%.bib$', '')
-- bibitem is assumed to be a list of inlines or MetaInlines element
or stringifyMetaInlines(bibitem):gsub('%.bib$', '')
end
local bibs = (type(bibliography) == 'List' or bibliography.t ==
'MetaList')
and List.map(bibliography, bibname)
or {bibname(bibliography)}
return table.concat(bibs, ',')
end
function aux_content(bibliography)
local cites = citation_ids()
table.sort(cites)
local citations = table.concat(cites, ',')
return table.concat(
{
'\\bibstyle{alpha}',
'\\bibdata{' .. bibdata(bibliography) .. '}',
'\\citation{' .. citations .. '}',
'',
},
'\n'
)
end
function write_dummy_aux (bibliography, auxfile)
local filename
if type(auxfile) == 'string' then
filename = auxfile
elseif type(auxfile) == 'table' or type(auxfile) == 'Inlines' then
-- assume list of inlines
filename = utils.stringify(pandoc.Span(auxfile))
else
filename = 'bibexport.aux'
end
local fh = io.open(filename, 'w')
fh:write(aux_content(bibliography))
fh:close()
io.stdout:write('Aux written to ' .. filename .. '\n')
return filename
end
function Pandoc (doc)
local meta = doc.meta
if not meta.bibliography then
return nil
else
-- create a dummy .aux file
local auxfile_name = write_dummy_aux(meta.bibliography, meta.auxfile)
os.execute('bibexport ' .. auxfile_name)
io.stdout:write('Output written to bibexport.bib\n')
return nil
end
end
```
We already have something that will collect the whole bibliography. How do
we go from this to actually using this to replace Cites with special
attributes? E.g. [@Citekey]{.title} or with a suffix [@Citekey-]? This last
one (the suffix) I was able to dig down until I could locate it in the
Pandoc AST using Paru for Ruby, but not using Lua. (At first, I thought Lua
would be easier, but the underlying Haskell architecture and the AST model
are still very foreign to me.)
Thanks,
B.
On Monday, January 30, 2023 at 2:41:35 PM UTC-3 John MacFarlane wrote:
> In a Lua filter you could probably just use pandoc.read with the format
> "bibtex" or "biblatex".
>
>
> > On Jan 30, 2023, at 9:21 AM, Bastien DUMONT <bastien...-VwIFZPTo/vqsTnJN9+BGXg@public.gmane.org>
> wrote:
> >
> > Do you mean a function that parses the .bib file directly? I really
> think that it would be easier to convert the .bib file to a CSL JSON file
> and import it via a JSON parser.
> >
> > Le Monday 30 January 2023 à 08:49:36AM, Bernardo C. D. A. Vasconcelos a
> écrit :
> >> Thanks for the feedback, Bastien!
> >> Can you think of a similar example script that contains the function to
> parse
> >> the bib data? I searched for it online to no avail.
> >> On Saturday, January 28, 2023 at 7:35:40 PM UTC-3 Bastien Dumont wrote:
> >>
> >> I think that it would be better to run it before citeproc, since you
> don't
> >> want citeproc output (unless you want to still benefit from the "ibid./
> >> cited" feature). Citeproc would not help you so much here because it
> does
> >> not tag the different parts of a formatted citation. On the other hand,
> >> parsing the bib file would be rather simple if it is in the CSL JSON
> >> format: then you would just have to use one of the JSON modules for Lua
> to
> >> import your bibliographic references into a Lua table. If you use
> Bib(La)
> >> TeX, you can convert a .bib file to a .json with `pandoc -f bibtex (or
> >> biblatex) -t csljson myfile.bib -o myfile.json`.
> >>
> >> Le Saturday 28 January 2023 à 02:07:54PM, Bernardo C. D. A. Vasconcelos
> a
> >> écrit :
> >>> An HTML equivalent of these commands was proposed in Github, but there
> >> was no
> >>> feasible way for it to be implemented as part of Citeproc. I suggested
> a
> >> Lua
> >>> filter to achieve this and John said it sounded doable.
> >>>
> >>> I learned some Lua and experimented, but I didn't come close enough to
> >> have
> >>> something worth sharing. In short: I imagined something like `[@Ref]
> >>> {.citetitle}` and `[@Ref]{.citeauthor}`. So this would imply: parsing
> the
> >> bib
> >>> data and saving it to a Lua table (stuck here); filtering spans;
> checking
> >> the
> >>> type and performing the replacement (not clear to me either what the
> >> correct
> >>> way would be to replace the id with the data or if this would have to
> run
> >>> before/after citeproc).
> >>>
> >>> Any pointers would be much appreciated.
> >>>
> >>> --
> >>> 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-discus...-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> >>> To view this discussion on the web visit [2][1]
> https://groups.google.com/
> >> d/msgid/
> >>> pandoc-discuss/51e71797-b029-4438-be64-6a8a15dd500an%[2]
> >> 40googlegroups.com.
> >>>
> >>> References:
> >>>
> >>> [1] mailto:pandoc-discus...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
> >>> [2] [3]https://groups.google.com/d/msgid/pandoc-discuss/
> >> 51e71797-b029-4438-be64-6a8a15dd500an%
> 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 [4]pandoc-discus...-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> >> To view this discussion on the web visit [5]
> https://groups.google.com/d/msgid/
> >> pandoc-discuss/4865a325-42c0-4245-b992-b4fbdeab576en%40googlegroups.com
> .
> >>
> >> References:
> >>
> >> [1] https://groups.google.com/d/msgid/
> >> [2] http://40googlegroups.com/
> >> [3]
> https://groups.google.com/d/msgid/pandoc-discuss/51e71797-b029-4438-be64-6a8a15dd500an%40googlegroups.com?utm_medium=email&utm_source=footer
> >> [4] mailto:pandoc-discus...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
> >> [5]
> https://groups.google.com/d/msgid/pandoc-discuss/4865a325-42c0-4245-b992-b4fbdeab576en%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-discus...-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> > To view this discussion on the web visit
> https://groups.google.com/d/msgid/pandoc-discuss/Y9f8i/Jl%2BgDjNo/a%40localhost
> .
>
>
--
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/4641cd0b-adb7-408f-b025-f56a0b293be5n%40googlegroups.com.
[-- Attachment #1.2: Type: text/html, Size: 13646 bytes --]
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Lua Filter for \citeauthor and \citetitle in HTML
[not found] ` <4641cd0b-adb7-408f-b025-f56a0b293be5n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2023-03-09 12:37 ` Albert Krewinkel
[not found] ` <87pm9i6qmx.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
0 siblings, 1 reply; 9+ messages in thread
From: Albert Krewinkel @ 2023-03-09 12:37 UTC (permalink / raw)
To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw
"Bernardo C. D. A. Vasconcelos" <bernardovasconcelos-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes:
> A filter that seems close enough is the bibexport filter at https://
> raw.githubusercontent.com/pandoc/lua-filters/master/bibexport/
> bibexport.lua which I reproduce below:
Newer pandoc versions allow to shorten this to
```
function Pandoc (doc)
doc.meta.references = pandoc.utils.references(doc)
doc.meta.bibliography = nil
return doc
end
```
Here's a "quick n' dirty" filter that should make your `[@key]{.title}`
syntax work:
```
function Pandoc (doc)
doc.meta.references = pandoc.utils.references(doc)
doc.meta.bibliography = nil
return doc:walk{
Span = function (span)
-- check that the span contains only a single cite object
local cite = span.content[1]
local citations = cite and cite.citations or nil
if #span.content == 1 and cite.t == 'Cite' and #citations == 1 then
local cite_id = citations[1].id
local ref = doc.meta.references:find_if(
function (r) return cite_id == r.id end
)
if ref and span.classes[1] then
-- replace the span with a specific citation field
return ref[span.classes[1]]
end
end
end
}
end
```
It's a bit condensed and not well documented, so let me know if you have
questions.
--
Albert Krewinkel
GPG: 8eed e3e2 e8c5 6f18 81fe e836 388d c0b2 1f63 1124
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Lua Filter for \citeauthor and \citetitle in HTML
[not found] ` <87pm9i6qmx.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
@ 2023-03-09 14:37 ` Bernardo C. D. A. Vasconcelos
[not found] ` <555cddba-b706-48f6-acb8-07465e5487a2n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
0 siblings, 1 reply; 9+ messages in thread
From: Bernardo C. D. A. Vasconcelos @ 2023-03-09 14:37 UTC (permalink / raw)
To: pandoc-discuss
[-- Attachment #1.1: Type: text/plain, Size: 2228 bytes --]
Albert,
that is vexingly short, but the syntax is perfectly clear. Thank you! Since
I toiled at this for a while, your filter will provide me with some
interesting learning opportunities. I will play around with it and see how
it behaves with the other Lua filters.
Thanks again,
B.
On Thursday, March 9, 2023 at 9:44:30 AM UTC-3 Albert Krewinkel wrote:
>
> "Bernardo C. D. A. Vasconcelos" <bernardov...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes:
>
> > A filter that seems close enough is the bibexport filter at https://
> > raw.githubusercontent.com/pandoc/lua-filters/master/bibexport/
> > bibexport.lua which I reproduce below:
>
> Newer pandoc versions allow to shorten this to
>
> ```
> function Pandoc (doc)
> doc.meta.references = pandoc.utils.references(doc)
> doc.meta.bibliography = nil
> return doc
> end
> ```
>
> Here's a "quick n' dirty" filter that should make your `[@key]{.title}`
> syntax work:
>
> ```
> function Pandoc (doc)
> doc.meta.references = pandoc.utils.references(doc)
> doc.meta.bibliography = nil
> return doc:walk{
> Span = function (span)
> -- check that the span contains only a single cite object
> local cite = span.content[1]
> local citations = cite and cite.citations or nil
> if #span.content == 1 and cite.t == 'Cite' and #citations == 1 then
> local cite_id = citations[1].id
> local ref = doc.meta.references:find_if(
> function (r) return cite_id == r.id end
> )
> if ref and span.classes[1] then
> -- replace the span with a specific citation field
> return ref[span.classes[1]]
> end
> end
> end
> }
> end
> ```
>
> It's a bit condensed and not well documented, so let me know if you have
> questions.
>
>
> --
> 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/555cddba-b706-48f6-acb8-07465e5487a2n%40googlegroups.com.
[-- Attachment #1.2: Type: text/html, Size: 3619 bytes --]
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Lua Filter for \citeauthor and \citetitle in HTML
[not found] ` <555cddba-b706-48f6-acb8-07465e5487a2n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2023-03-09 18:56 ` Bernardo C. D. A. Vasconcelos
0 siblings, 0 replies; 9+ messages in thread
From: Bernardo C. D. A. Vasconcelos @ 2023-03-09 18:56 UTC (permalink / raw)
To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw
[-- Attachment #1: Type: text/plain, Size: 5314 bytes --]
It works wonderfully. I made some minor modifications to allow it to work more like a `citefield` filter in general, and to avoid an error due to invalid field names passed as args. I think we could call it ready unless anyone else has suggestions. For fields with names such as authors, editors and translators, it seemed enough to get the family name of the first name, but other could prefer it to behave differently, of course.
```
local function get_keys(t)
local keys={}
for key,_ in pairs(t) do
table.insert(keys, key)
end
return keys
end
stringify = require 'pandoc.utils'.stringify
function Pandoc (doc)
doc.meta.references = pandoc.utils.references(doc)
doc.meta.bibliography = nil
return doc:walk{
Span = function (span)
-- check that the span contains only a single cite object
local cite = span.content[1]
local citations = cite and cite.citations or nil
if #span.content == 1 and cite.t == 'Cite' and #citations == 1 then
local cite_id = citations[1].id
local ref = doc.meta.references:find_if(
function (r) return cite_id == r.id end
)
local the_arg = span.classes[1]
local the_result = ""
if ref and the_arg then
if string.find(stringify(get_keys(ref)), the_arg) then
-- replace the span with a specific citation field
if the_arg == "author" or the_arg == "editor" or the_arg == "translator" then
the_result = stringify(ref[the_arg][1]["family"])
else if the_arg == "title" then
the_result = pandoc.Emph{stringify(ref[the_arg])}
else
the_result = stringify(ref[the_arg])
end
end
else
-- return the span unchanged
the_result = span
end
return the_result
end
end
end
}
end
```
Um abraço,
Bernardo
From: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org <pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> on behalf of Bernardo C. D. A. Vasconcelos <bernardovasconcelos-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Date: Thursday, 9 March 2023 11:37
To: pandoc-discuss <pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
Subject: Re: Lua Filter for citeauthor and citetitle in HTML
Albert,
that is vexingly short, but the syntax is perfectly clear. Thank you! Since I toiled at this for a while, your filter will provide me with some interesting learning opportunities. I will play around with it and see how it behaves with the other Lua filters.
Thanks again,
B.
On Thursday, March 9, 2023 at 9:44:30 AM UTC-3 Albert Krewinkel wrote:
"Bernardo C. D. A. Vasconcelos" <bernardov...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes:
> A filter that seems close enough is the bibexport filter at https://
> raw.githubusercontent.com/pandoc/lua-filters/master/bibexport/<http://raw.githubusercontent.com/pandoc/lua-filters/master/bibexport/>
> bibexport.lua which I reproduce below:
Newer pandoc versions allow to shorten this to
```
function Pandoc (doc)
doc.meta.references = pandoc.utils.references(doc)
doc.meta.bibliography = nil
return doc
end
```
Here's a "quick n' dirty" filter that should make your `[@key]{.title}`
syntax work:
```
function Pandoc (doc)
doc.meta.references = pandoc.utils.references(doc)
doc.meta.bibliography = nil
return doc:walk{
Span = function (span)
-- check that the span contains only a single cite object
local cite = span.content[1]
local citations = cite and cite.citations or nil
if #span.content == 1 and cite.t == 'Cite' and #citations == 1 then
local cite_id = citations[1].id
local ref = doc.meta.references:find_if(
function (r) return cite_id == r.id<http://r.id> end
)
if ref and span.classes[1] then
-- replace the span with a specific citation field
return ref[span.classes[1]]
end
end
end
}
end
```
It's a bit condensed and not well documented, so let me know if you have
questions.
--
Albert Krewinkel
GPG: 8eed e3e2 e8c5 6f18 81fe e836 388d c0b2 1f63 1124
--
You received this message because you are subscribed to a topic in the Google Groups "pandoc-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/pandoc-discuss/5gb64T4OU9Q/unsubscribe.
To unsubscribe from this group and all its topics, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<mailto:pandoc-discuss+unsubscribe@googlegroups.com>.
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/555cddba-b706-48f6-acb8-07465e5487a2n%40googlegroups.com<https://groups.google.com/d/msgid/pandoc-discuss/555cddba-b706-48f6-acb8-07465e5487a2n%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/CY4PR08MB3495899DCBA5868E92EE0F0CF2B59%40CY4PR08MB3495.namprd08.prod.outlook.com.
[-- Attachment #2: Type: text/html, Size: 36858 bytes --]
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2023-03-09 18:56 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-28 22:07 Lua Filter for \citeauthor and \citetitle in HTML Bernardo C. D. A. Vasconcelos
[not found] ` <51e71797-b029-4438-be64-6a8a15dd500an-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2023-01-28 22:35 ` Bastien DUMONT
2023-01-30 16:49 ` Bernardo C. D. A. Vasconcelos
[not found] ` <4865a325-42c0-4245-b992-b4fbdeab576en-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2023-01-30 17:21 ` Bastien DUMONT
2023-01-30 17:41 ` John MacFarlane
[not found] ` <9786B5A5-9022-4E5B-85DE-39D4A2CAFD8F-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2023-03-08 14:00 ` Bernardo C. D. A. Vasconcelos
[not found] ` <4641cd0b-adb7-408f-b025-f56a0b293be5n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2023-03-09 12:37 ` Albert Krewinkel
[not found] ` <87pm9i6qmx.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
2023-03-09 14:37 ` Bernardo C. D. A. Vasconcelos
[not found] ` <555cddba-b706-48f6-acb8-07465e5487a2n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2023-03-09 18:56 ` Bernardo C. D. A. Vasconcelos
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).