[NTG-context] Different layout for specific pages

2019-08-23 Thread Stanislav Sokolenko

Dear list,

I would like to specify in advance that certain pages are to have 
different layouts. I put together an example based on what read on the 
wiki (https://wiki.contextgarden.net/Layout#Multiple_layouts):


\setuppapersize[A6]

\definelayout[bigheader][header=0.5\textheight]
\definelayout[smallheader][header=0.1\textheight]

\setuplayout[smallheader]
\definelayout[1][bigheader]
\definelayout[2][smallheader]

\starttext
\showframe
\input knuth
\input knuth
\input knuth
\stoptext

However, rather then having the big header only on page 1, I end up with 
it on every page except page 2. Is this a bug or can someone tell me 
what I'm doing wrong? I've tried using the lmtx binaries, a recent 
context standalone version (2019-08-17) and using context live with the 
same result everywhere.


Thanks,

Stan

___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___


Re: [NTG-context] Get list of all buffer names from lua

2019-01-07 Thread Stanislav Sokolenko

On 2019-01-07 9:06 p.m., Henri Menke wrote:


On 8/01/19 1:37 PM, Stanislav Sokolenko wrote:

Dear list,

As the subject line states, I am looking for a means of retrieving a
table of all saved buffer names from lua. A MNWE would looks like:

It's not so easy because ConTeXt stores the buffers in a local variable
`cache` which is an upvalue for all the other functions.  However, you
can use the Lua `debug` library to access upvalues.  I access the first
upvalue of `buffers.erase`, because it only has a single upvalue which
is `cache`.  Then I can easily extract all the names from that.  You
can't get them in the order of declaration because `cache` is a hashmap
and not an array.  Moreover, ConTeXt is usually in sandboxing mode.  To
get access to the `debug` library you have to run ConTeXt with

 context --debug test.tex

MWE:

\starttext
\startbuffer[ex1]
Buffer 1
\stopbuffer
\startbuffer[ex2]
Buffer 2
\stopbuffer
% Should return {ex1, ex2} or similar
\startluacode
local _, cache = debug.getupvalue(buffers.erase,1)
local names = {}
for name,_ in pairs(cache) do
 names[#names+1] = name
end
context(table.concat(names,", "))
\stopluacode
\stoptext


That's perfect, thank you! I did see the cache variable in buff-ini.lua 
but didn't realize it was being used as an upvalue in a closure. Is 
there a specific reason for using the --debug flag rather than just 
loading the debug module directly in the code? The following seems to 
work without the --debug flag but I want to make sure I'm not causing 
some sort of side effect.


\starttext
\startbuffer[ex1]
Buffer 1
\stopbuffer
\startbuffer[ex2]
Buffer 2
\stopbuffer
% Should return {ex1, ex2} or similar
\startluacode
local debug = require('debug')
local _, cache = debug.getupvalue(buffers.erase,1)
local names = {}
for name,_ in pairs(cache) do
    names[#names+1] = name
end
context(table.concat(names,", "))
\stopluacode
\stoptext




\starttext
\startbuffer[ex1]
Buffer 1
\stopbuffer
\startbuffer[ex2]
Buffer 2
\stopbuffer
% Should return {ex1, ex2} or similar
\ctxlua{context(...)}
\stoptext

The underlying idea is to store a large number of example problems in
individual buffers that could be retrieved either by specific name or as
a complete list. I'm having a problem with the latter as it seems like
all the lua buffer commands I've encountered assume that buffer names
are known in advance:

buffers.getcontent(b)
buffers.raw(b)
buffers.getlines(b)
buffers.erase(b)
buffers.assign(b, text, catcodes)
buffers.append(b, text)
buffers.exists(b)
buffers.collectcontent(names, seperator)

Thanks,

Stan



___

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

maillist : ntg-context@ntg.nl /
http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___

___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___

___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___

[NTG-context] Get list of all buffer names from lua

2019-01-07 Thread Stanislav Sokolenko

Dear list,

As the subject line states, I am looking for a means of retrieving a 
table of all saved buffer names from lua. A MNWE would looks like:


\starttext
\startbuffer[ex1]
Buffer 1
\stopbuffer
\startbuffer[ex2]
Buffer 2
\stopbuffer
% Should return {ex1, ex2} or similar
\ctxlua{context(...)}
\stoptext

The underlying idea is to store a large number of example problems in 
individual buffers that could be retrieved either by specific name or as 
a complete list. I'm having a problem with the latter as it seems like 
all the lua buffer commands I've encountered assume that buffer names 
are known in advance:


buffers.getcontent(b)
buffers.raw(b)
buffers.getlines(b)
buffers.erase(b)
buffers.assign(b, text, catcodes)
buffers.append(b, text)
buffers.exists(b)
buffers.collectcontent(names, seperator)

Thanks,

Stan



___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___

Re: [NTG-context] Can anyone connect context to R or python?

2018-10-08 Thread Stanislav Sokolenko

On 2018-10-06 02:06 PM, Aditya Mahajan wrote:



I also want to take this opportunity to express my views on intefacing 
with external programs. The file based interaction provided by the 
filter module is okay for small projects but it is not ideal. Slightly 
better is to use pipes (popen to a REPL) or use FFI (e.g 
https://adityam.github.io/context-blog/post/interfacing-with-julia), 
but neither of these is easy to implement and needs to be done on a 
per-language basis. Henri Menke had a Tugboat article on this as well.


In my opinion, a better long-term option is to write a jupyter client 
in lua that can be called by context. Then we can easily interface 
with all languages that provide a jupyter kernel 
(https://github.com/jupyter/jupyter/wiki/Jupyter-kernels).


The interface of a jupter-client is available here
https://jupyter-client.readthedocs.io/en/stable/index.html. It seems 
relatively straight forward (send a JSON message and receive a JSON 
message). Translating the JSON messages to ConTeXt should also be 
easy. Is there anyone who wants to play around trying to implement this?




I have recently come across the SciLua project 
(http://scilua.org/index.html) which has a built-in LuaJIT client for 
Rserve (http://scilua.org/rclient.html) and may be relevant to the 
discussion. Although it certainly isn't as general as something like 
jupyter, leaning on SciLua may be an easier means of getting access to 
scientific computation with R and basic numerical methods. I am 
personally planning to look into switching from filter to SciLua if it 
means that I can get more efficient data transfer between R and ConTeXt. 
But I'm a ConTeXt and Lua neophyte so I doubt my personal efforts will 
be translatable into something more general like a module.


Stan

___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___

Re: [NTG-context] Modifying bibliography entries using lua

2018-07-24 Thread Stanislav Sokolenko

That's perfect, thank you!

On 2018-07-23 06:32 PM, Hans Hagen wrote:

\startsetups btx:list:author:normalshort
    \fastsetup{btx:list:author:concat}
    \begingroup

\ctxluacode{document.CheckMeB("\currentbtxdataset","\currentbtxtag",\number\currentbtxauthorindex)} 


    \ifx\currentbtxinitials\empty \else
    \currentbtxinitials
    \btxparameter{separator:initials}
    \fi
    \ifx\currentbtxvons\empty \else
    \currentbtxvons
    \ifx\currentbtxsurnames\empty \else
    \btxparameter{separator:vons}
    \fi
    \fi
    \ifx\currentbtxsurnames\empty \else
    \currentbtxsurnames
    \ifx\currentbtxjuniors\empty \else
    \btxparameter{separator:juniors}
    \currentbtxjuniors
    \fi
    \fi
    \endgroup
    \fastsetup{btx:list:author:others}
\stopsetups 


I went with the following little extension to match and make bold 
multiple names:


|\startbuffer[ref]@article{solo, author ={MyLast, MyFirst}, title ={Solo 
work}, journal ={Journal}, year ={2000}, month ={1}, volume 
={1}}@article{co, author ={OtherLast, OtherFirst and MyLast, MyFirst and 
CoLast, CoFirst}, title ={Joint work}, journal ={Journal}, month ={1}, 
year ={2000}, volume 
={1}}\stopbuffer\usebtxdataset[ref][ref.buffer]\setupbtx[dataset=ref]\definebtxrendering[ref][dataset=ref]\setupbtx[default:cite][alternative=authoryear, 
etallimit=1, authorconversion=normalshort]\startluacodeBoldNames 
={{firstnames ="MyFirst", surnames ="MyLast"}, {initials ="C", surnames 
="CoLast"}, }function document.CompareNames(reference, targets)-- Loop 
over targets for _, target in pairs(targets)do -- Loop over fields for 
key, value in pairs(target)do if reference[key]==nil then break end 
full_entry ='' for _, part in ipairs(reference[key])do full_entry 
=full_entry .. ' ' .. part end full_entry =string.sub(full_entry, 2)if 
full_entry ==value then return(true)end end end return(false)end 
function document.BoldNames(set, tag, aut)local c 
=publications.getcasted(set, tag, "author")if 
document.CompareNames(c[aut], BoldNames)then context("\\bf")end end 
\stopluacode\startsetupsbtx:list:author:normalshort 
\fastsetup{btx:list:author:concat}\begingroup\ctxluacode{document.BoldNames("\currentbtxdataset","\currentbtxtag",\number\currentbtxauthorindex)}\ifx\currentbtxinitials\empty\else\currentbtxinitials\btxparameter{separator:initials}\fi\ifx\currentbtxvons\empty\else\currentbtxvons\ifx\currentbtxsurnames\empty\else\btxparameter{separator:vons}\fi\fi\ifx\currentbtxsurnames\empty\else\currentbtxsurnames\ifx\currentbtxjuniors\empty\else\btxparameter{separator:juniors}\currentbtxjuniors\fi\fi\endgroup\fastsetup{btx:list:author:others}\stopsetups\starttextCitations: 
\cite[solo]\cite[co]\startsubject[title=Bibliography]\placelistofpublications[ref][method=dataset]\stopsection\stoptext|



Cheers,

Stan

___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___

Re: [NTG-context] Modifying bibliography entries using lua

2018-07-23 Thread Stanislav Sokolenko

Thanks Hans, that's really helpful!


This is not for the fainthearted so here we go

\startluacode
    function document.MyBoldPub(set,tag)
 -- local a = publications.getfield(set,tag,"author")
 -- inspect(a)
 -- local c = publications.getcasted(set,tag,"author")
 -- inspect(c)
    if c[1].surnames[1] == "Myname" then
    context.bold(function()
    context.btxflush('author')
    end )
    else
    context.btxflush('author')
    end
    end
\stopluacode


So if I wanted to bold one specific author in a reference of many, I can 
just loop over publications.getcasted(...), and print the appropriate 
names, initials, etc...


That said -- is there any way to call the appropriate authorconversion 
routine based on the \setupbtx settings? I found the 
publications.authorhashers method table, which seems to do most of this 
work, but I'm not sure how to pick the appropriate method and ensure 
that the correct separators are used.


Stan


___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___

[NTG-context] Modifying bibliography entries using lua

2018-07-23 Thread Stanislav Sokolenko

Dear list,

I'm struggling to output bibliography entries into lua for string 
modification (like making a particular author name bold). In effect, I 
just need something like the following:


\starttexdefinition btx:customauthor
    \startluacode
    local text = context.btxflush('author')
    -- tex.sprint(text) -- fails because text remains nil
    \stopluacode
\stoptexdefinition

It's clear that btxflux is the wrong function for this as it writes the 
contents to file rather than returning a variable in lua... Is there a 
way to directly access what btxflush is writing through the publications 
table or other means? I've gone over the source code but I can't 
decipher what btxflush is actually doing.


Thanks,

Stan

Longer MNWE:

\stopluacode

\startbuffer[ref]
@article{solo,
  author = {Lastname, Firstname},
  title = {Solo work},
  journal = {Journal},
  year = {2000},
  month = {1},
  volume = {1}
}
\stopbuffer

\usebtxdataset[ref][ref.buffer]
\setupbtx[dataset=ref]

\definebtxrendering[ref][dataset=ref]
\setupbtx[default:cite]
  [alternative=authoryear,
   etallimit=1]


\starttexdefinition btx:customauthor
    \startluacode
    local text = context.btxflush('author')
    -- tex.sprint(text) -- text remains nill
    \stopluacode
\stoptexdefinition

\startsetups btx:default:list:article
    \texdefinition{btx:customauthor}
    \texdefinition{btx:default:title}
    \texdefinition{btx:default:journal}
    \texdefinition{btx:default:year}
    \removeunwantedspaces
    \removepunctuation
    \btxperiod
\stopsetups

\starttext

Citations: \cite[solo]

\startsubject[title=Bibliography]
\placelistofpublications[ref][method=dataset]
\stopsection

\stoptext


___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___

[NTG-context] Finding lua file for module using \registerctxluafile

2018-07-18 Thread Stanislav Sokolenko

Dear list,

I've recently written a small module p-mymod.tex which uses lua code in 
p-mymod.lua. In order to load this lua code, I use 
\registerctxluafile{p-mymod}{1.001} (copying the example of 
m-database.mkiv). However, it seems like the search path for lua files 
isn't the same as for context module files.


When a context file that uses p-mymod through \usemodule[mymod] is 
placed in a subdirectory, it finds p-mymod, but not the lua portion:


p-mymod.tex
p-mymod.lua
subdir/test.tex

Placing the lua file inside the subdirectory resolves this problem:

p-mymod.tex
subdir/p-mymod.lua
subdir/test.tex

What is the suggested method to change the lua search path? Ideally, I'd 
like to avoid placing the files in 
$TEXMF/tex/context/third// as this module is quite 
intimately tied to the specific project and it doesn't make much sense 
to separate the files too much.


Thanks,

Stan



___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___

Re: [NTG-context] mtxrun fails to install fonts

2018-07-04 Thread Stanislav Sokolenko

Hi Hans,

On 2018-07-04 04:32 AM, Hans Hagen wrote:

Can you test the beta from the contextgarden?


The beta works with no problems, thanks!

I have also played around with my older installation some more and it 
seems like the original problem was related to the font cache.


I have previously tried deleting the cache (with no effect) using:

mtxrun --script cache --erase --fonts

However, I have just now realized that running the same command with 
sudo deleted a different cache (/var/... vs /home/...):


sudo mtxrun --script cache --erase --fonts

Once both caches were deleted, the fonts were identified and installed 
with no problems.


I'm not sure how to recreate this issue with the beta install, but maybe 
it was just a quirk of my particular system.


Cheers,

Stan

___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___

[NTG-context] mtxrun fails to install fonts

2018-07-03 Thread Stanislav Sokolenko

Dear list,

I have what seems to be an OS- or ConTeXt version-specific issue with 
mtxrun installing fonts.


I've been trying to add new truetype fonts (specifically Archivo ttf 
files) on Arch Linux using the following command:


export OSFONTDIR=~/.fonts//; mtxrun --script font --reload

And I've been using the following to check the installation:

mtxrun --script font --list --all --pattern=*archi*

It seems like a relatively new version of ConTeXt on Arch Linux 
(2018.04.04 00:51) recognizes but does not install the ttf files located 
in ~/.fonts/. The (shortened) output is:


fonts   | names | identifying system font files with suffix 'ttf'
fonts   | names | globbing path '/home/stanislav/.fonts/**.ttf'
fonts   | names | identifying system font files with suffix 'TTF'
fonts   | names | globbing path '/home/stanislav/.fonts/**.TTF'
fonts   | names | 8 system files identified, 0 skipped, 0 
duplicates, 8 hash entries added, runtime 0.006 seconds


But when I check the installation, no Archivo files are found.

Strangely, an older installation on Linux Mint (2015.05.18 12:26) has no 
problems with the same ttf files:


fonts   | names | globbing path '/home/stanislav/.fonts/**.ttf'
fonts   | names | identifying system font files with suffix 'TTF'
fonts   | names | globbing path '/home/stanislav/.fonts/**.TTF'
fonts   | names | 8 system files identified, 0 skipped, 0 
duplicates, 8 hash entries added, runtime 0.000 seconds


And the check:

mtxrun --script font --list --all --pattern=*archi*

archivo archivomedium 
/home/stanislav/.fonts/typecatcher/Archivo_500.ttf
archivobold archivobold 
/home/stanislav/.fonts/typecatcher/Archivo_700.ttf
archivobolditalic   archivobolditalic 
/home/stanislav/.fonts/typecatcher/Archivo_700italic.ttf
archivodemi archivosemibold 
/home/stanislav/.fonts/typecatcher/Archivo_600.ttf
archivoitalic   archivoitalic 
/home/stanislav/.fonts/typecatcher/Archivo_italic.ttf
archivomedium   archivomedium 
/home/stanislav/.fonts/typecatcher/Archivo_500.ttf
archivomediumitalic archivomediumitalic 
/home/stanislav/.fonts/typecatcher/Archivo_500italic.ttf
archivonormal   archivoitalic 
/home/stanislav/.fonts/typecatcher/Archivo_italic.ttf
archivoregular  archivoregular 
/home/stanislav/.fonts/typecatcher/Archivo_regular.ttf
archivosemibold archivosemibold 
/home/stanislav/.fonts/typecatcher/Archivo_600.ttf
archivosemibolditalic   archivosemibolditalic 
/home/stanislav/.fonts/typecatcher/Archivo_600italic.ttf


I've been searching for a couple of days and I'm at a loss. Is there a 
way to check why the identified system files aren't being installed?


Thanks,

Stan

___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___

Re: [NTG-context] definenote and localfootnotes

2017-11-03 Thread Stanislav Sokolenko


Hi Stanislav, footnotes are only one kind of notes. Not all notes are 
footnotes. If you ask for footnotes, you will only get footnotes


Thanks Pablo, I had a feeling that was the case, but all the examples I 
ran across seemed to have the two conflated. Your example is perfect!


BTW, I wonder whether it makes sense to have both kind of notes to 
share numbering. 


I see now that notes don't have to inherit from footnotes.

Thanks again,

Stan
___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___

[NTG-context] definenote and localfootnotes

2017-11-03 Thread Stanislav Sokolenko

Hi,

I'm not sure if this is a bug or feature, but I noticed that custom 
footnotes defined through \definenote do not appear when using 
\placelocalfootnotes as per the following example:


%
\setuppapersize [A5]

\definenote [noteone] [footnote]
\setupnotation [noteone] [style=bold, headstyle=bold]
\setupnote [noteone] [textstyle=bold]

\starttext
  \startlocalfootnotes
  Testing footnote \footnote{this is a footnote}
  Testing noteone \noteone{this is noteone}
  \placelocalfootnotes
  \stoplocalfootnotes

  Testing footnote \footnote{this is a footnote}
  Testing noteone \noteone{this is noteone}
\stoptext
%

Both the local and global footnotes appear as 1, 2 (so noteone is 
numbered locally). Is there an alternative command to 
\placelocalfootnotes that I can use to make noteone appear in the local 
context?


Thanks,

Stan
___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___