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 Answers1

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

  • Can you please put the reference of feature request to the mailing list? – somenxavier Apr 29 '21 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 – somenxavier Apr 29 '21 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```

    – somenxavier Apr 29 '21 at 21:31
  • @jairo-a-del-rio I edit the original question. I hope this helps you – somenxavier Apr 29 '21 at 21:31
  • Testing new code, I get carriage return before \listofcalledmodes. Is there any way to just give a space before that: something like foo amode anothermode ... instead of `foo \n amode anothermode..."? – somenxavier May 20 '21 at 14:11
  • @HenriMenke Just for curiosity. Can you give an alternative answer? with return? – somenxavier May 20 '21 at 14:13
  • 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 –  May 20 '21 at 14:35
  • I don't see par in your new code – somenxavier May 20 '21 at 16:35
  • @somenxavier Yeah, I removed it as it was starting a new paragraph. Isn't that what you're asking for? Please clarify so that I can help –  May 20 '21 at 18:34
  • Yes, Jairo. It's definitvely what I want. – somenxavier May 21 '21 at 09:33