0

I need something in document like this

\listcallingmodes

which return the list of calling modes, that is, if I run

context --mode=mode1,mode2 file.tex

in file.tex:

\starttext

\startmode[a1]
This is mode a1
\stopmode

Hello

\listcallingmodes
\stoptext

which I would to get

Hellp

mode1 mode2

Note that in this file we could have other modes than calling modes

1 Answer 1

2

NEW ANSWER:

If you only need those modes called via the command line, this task is easier. Since ConTeXt stores command line data in the environment namespace, let's take advantage of this:

\startluacode
local listofcalledmodes = function()
    local split = string.split
    local flag  = '^--c:mode='
    local concat = table.concat
    for _, v in pairs(environment.originalarguments) do
        if v:find(flag) then
            local w = split(v:gsub(flag, ""), ",")
            context(concat(w, " ")) 
            return  
        end
    end
    context("No modes set")
end

interfaces.implement{
    name   = "listofcalledmodes",
    public = true,
    actions = listofcalledmodes
}
\stopluacode
\starttext
\startTEXpage
My list of modes: \listofcalledmodes
\stopTEXpage
\stoptext

Compiling your file the following way (159.tex is my file):

context --mode=amode,anothermode,toomanymodes 159.tex

I get the following result:

enter image description here

OLD ANSWER:

I'll ask for a feature request to the mailing list so a proper macro is available. In the meantime, the following should do the work most of times. Since modes are registered at the TeX end with as command sequences named with a mode> prefix (in core-env.mkiv and core-env.mkxl), we can look up at them in tex.hashtokens (related discussion here). However, if I get you right, you don't want system modes (internal, marked with an asterisk), so they will be filtered out:

\startluacode
local function listofmodes()
    local s1, s2  = "^mode>[^%*]+", "^mode>"
    context.blank() -- change this ad libitum
    for _, v in pairs(tex.hashtokens()) do
        if v:find(s1) and tex.modes[v:gsub(s2, "")] then
            context(v:gsub(s2, ""))
            context.par() -- also change this if needed
        end
    end
end

interfaces.implement{
    name    = "listofmodes",
    public  = true,
    actions = listofmodes
}
\stopluacode
\starttext
Hi, there's a list of used modes: \listofmodes
\stoptext

However, you may need a workaround, setting hash_extra=0 in some cases (issue discussed here), so you're warned.

enter image description here

10
  • Can you please put the reference of feature request to the mailing list? Commented Apr 29, 2021 at 14:04
  • I only get mkiv in my document and I run context --mode=espa1,espa1a,espa2,espa2a,espa3,espa3a,espa4,espa4a --nonstopmode --noconsole --purgeall myfile.conTeXt Commented Apr 29, 2021 at 14:12
  • @jairo-a-del-rio It does not work for me: \startluacode local function listofmodes() local s1, s2 = "^mode>[^%*]+", "^mode>" context.blank() -- change this ad libitum for _, v in pairs(tex.hashtokens()) do if v:find(s1) and tex.modes[v:gsub(s2, "")] then context(v:gsub(s2, "")) end end end interfaces.implement{ name = "listofmodes", public = true, actions = listofmodes } \stopluacode \starttext \startmode[a1] Això és a1 \stopmode Jols \stoptext Commented Apr 29, 2021 at 21:31
  • @jairo-a-del-rio I edit the original question. I hope this helps you Commented Apr 29, 2021 at 21:31
  • 1
    @somenxavier I put par (or context.par() in the Lua side) on purpose. You only need to remove it and change goto done by return. I'll edit my answer Commented May 20, 2021 at 14:35

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.