ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* [NTG-context] Cite-proc Lua - Following up
@ 2024-06-11 11:38 hdanielhixson
  2024-06-12 10:56 ` [NTG-context] " Max Chernoff
  0 siblings, 1 reply; 2+ messages in thread
From: hdanielhixson @ 2024-06-11 11:38 UTC (permalink / raw)
  To: ntg-context

Hello all,

I hope you are well. This is my first time posting. So if I do so erroneously, I apologize. 

There is a LaTeX package called citation-style-language, backed by some software called citeproc-lua. The github page for the software is here: https://github.com/zepinglee/citeproc-lua

It is an excellent piece of software.

There was previous discussion about potentially integrating the software into Context. The following link should show a discussion that took place about the topic.
https://www.mail-archive.com/search?l=ntg-context@ntg.nl&q=subject:%22Re%5C%3A+%5C%5BNTG%5C-context%5C%5D+Citeproc%5C-lua%22&o=newest

I'm just wondering if there is more news about its potential integration with Context.

Thank you, devs, for your hard work on making the software.
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki     : https://wiki.contextgarden.net
___________________________________________________________________________________

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

* [NTG-context] Re: Cite-proc Lua - Following up
  2024-06-11 11:38 [NTG-context] Cite-proc Lua - Following up hdanielhixson
@ 2024-06-12 10:56 ` Max Chernoff
  0 siblings, 0 replies; 2+ messages in thread
From: Max Chernoff @ 2024-06-12 10:56 UTC (permalink / raw)
  To: hdanielhixson; +Cc: ntg-context

Hi,

On Tue, 2024-06-11 at 11:38 +0000, hdanielhixson@gmail.com wrote:
> There is a LaTeX package called citation-style-language, backed by
> some software called citeproc-lua. The github page for the software is
> here: https://github.com/zepinglee/citeproc-lua

> I'm just wondering if there is more news about its potential
> integration with Context.

A *very* quick and hacky implementation. First, clone the repository
plus all its submodules, then apply two small patches for Lua 5.5
compatibility:

    diff --git a/citeproc/citeproc-latex-core.lua b/citeproc/citeproc-latex-core.lua
    index 3057c5d..95c917a 100644
    --- a/citeproc/citeproc-latex-core.lua
    +++ b/citeproc/citeproc-latex-core.lua
    @@ -260,6 +260,7 @@ end
     local function parse_latex_seq(s)
       local t = {}
       for item in string.gmatch(s, "(%b{})") do
    +    local item = item
         item = string.sub(item, 2, -2)
         table.insert(t, item)
       end

    diff --git a/luaxml-mod-xml.lua b/luaxml-mod-xml.lua
    index d40b761..bf09830 100644
    --- a/luaxml-mod-xml.lua
    +++ b/luaxml-mod-xml.lua
    @@ -524,6 +524,7 @@ local function getAttributes(k,v)
       level = level or 0
       local spaces = string.rep(' ', level*2)
       for k,v in pairs(tb) do
    +    local k = k
         if type(v) ~= "table" then
           local ct = k
           if type(k)=="number" then

Then, install all the files somewhere where ConTeXt can find them. The
following layout seems to work:

    $ tree -a $TEXMFHOME
    /home/max/Projects/citeproc-lua/texmf/
    ├── scripts
    │   ├── citation-style-language -> ../../citeproc/
    │   └── lua-uca -> ../../submodules/lua-uca/src/lua-uca/
    └── tex
        ├── generic
        │   └── unicode-data -> ../../../submodules/unicode-data/
        ├── latex
        │   └── citation-style-language -> ../../../latex/
        └── luatex
            ├── lua-uni-algos -> ../../../submodules/lua-uni-algos/
            └── luaxml -> ../../../submodules/luaxml/

    12 directories, 0 files

Finally, make a new file somewhere in the "examples/" folder with the
following contents:

    \startluacode
        package.loaded.unicode = { utf8 = string }
        package.loaded.lualibs = {}
        kpse.find_file = function(name)
            local path = resolvers.findfile(name)
            if path == "" then
                path = nil
            end
            return path
        end

        local saved_require = require
        function require(name)
            return saved_require(name:gsub("^[^%.]+%.", ""))
        end

        require("util-jsn")

        local output = require("citeproc-output")
        local ConTeXtWriter = output.LatexWriter

        ConTeXtWriter.markups = {
            ["bibstart"] = [[\startitemize]],
            ["bibend"] = [[\stopitemize]],
            ["@font-style/normal"] = [[\normal{%s}]],
            ["@font-style/italic"] = [[\italic{%s}]],
            ["@font-style/oblique"] = [[\slanted{%s}]],
            ["@font-variant/normal"] = "[[\normal{%s}]]",
            ["@font-variant/small-caps"] = [[{\sc %s}]],
            ["@font-weight/normal"] = "[[\normal{%s}]]",
            ["@font-weight/bold"] = [[\bold{%s}]],
            ["@font-weight/light"] = "[[\normal{%s}]]",
            ["@text-decoration/none"] = false,
            ["@text-decoration/underline"] = [[\underline{%s}]],
            ["@vertical-align/sup"] = [[\high{%s}]],
            ["@vertical-align/sub"] = [[\low{%s}]],
            ["@vertical-align/baseline"] = false,
            ["@cite/entry"] = false,
            ["@bibliography/entry"] = [[\item %s]] .. "\n"
        }

        function ConTeXtWriter:write_escaped(str, context)
            return string.formatters["%!tex!"](str)
        end

        function ConTeXtWriter:write_link(inline, context)
            if inline.href == inline.value then
                -- URL
                return string.format([[\hyphenatedurl{%s}]], inline.value)
            elseif context.engine.opt.wrap_url_and_doi then
                return string.format([=[\goto{\hyphenatedurl{%s}}[url(%s)]]=], inline.href, self:write_escaped(inline.value, context))
            else
                return self:write_escaped(inline.value, context)
            end
        end

        local engine
        interfaces.implement {
            name = "cslinit",
            public = true,
            arguments = "2 strings",
            actions = function(style_name, bib_file)
                local citeproc = require("citeproc")
                local latex_core = require("citeproc-latex-core")
                local citeproc_sys = latex_core.make_citeproc_sys { bib_file }
                local style = latex_core.read_file(style_name .. ".csl")
                engine = citeproc.new(citeproc_sys, style)
                engine.output_format = ConTeXtWriter
            end
        }

        interfaces.implement {
            name = "cslcite",
            public = true,
            arguments = "string",
            actions = function(key)
                context(engine:makeCitationCluster { { id = key } })
            end
        }

        interfaces.implement {
            name = "cslbibliography",
            public = true,
            actions = function()
                local params, items = table.unpack(engine:makeBibliography())
                context(params.bibstart)
                for _, item in ipairs(items) do
                    context(item)
                end
                context(params.bibend)
            end
        }
    \stopluacode

    \cslinit{apa}{example.json}

    \starttext
        A \cslcite{ITEM-1} B \cslcite{ITEM-2} C \cslcite{ITEM-3} D \cslcite{ITEM-4}.

        \cslbibliography
    \stoptext

I've only tested this with the exact example from the README, so it will
probably break for anything even slightly more complex. Improving this
is left as an exercise for the reader :)

Thanks,
-- Max
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki     : https://wiki.contextgarden.net
___________________________________________________________________________________

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

end of thread, other threads:[~2024-06-12 10:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-11 11:38 [NTG-context] Cite-proc Lua - Following up hdanielhixson
2024-06-12 10:56 ` [NTG-context] " Max Chernoff

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