5

I was reading the TUG interview with Pavneet Arora who was this year organizer of TUG meeting in Toronto and one thing caught my attention. Mr Arora described use of ConTeXt to develop “specification-driven documentation” with an emphasis on YAML as a main trust of his current professional work. YAML as some people probably know is human-readable data serialization language but more importantly for me personally is the language used to write play books for Ansible, a widely used configuration, management, and orchestration software.

Unfortunately I was not quite able to understand the connection between ConTeXt and YAML described in the above article so here I plea for help. Could anybody kindly describe to me the relationship between ConTeXt and YAML? I have this vague idea that would be possible to write Ansible play book in ConTeXt which will then be able "TeX" into YAML play book but also into the printable documentation. The idea of course is not original and people will recognize Don Knuth's WEB which can produce both Pascal code and printable TeX document.

  • 1
    Vagueness is in vogue, perhaps? – cfr Aug 10 '16 at 3:36
  • 1
    Maybe you could email Pavneet to ask for more details. – Aditya Aug 10 '16 at 4:10
  • 2
    »... along with scripts to generate the desired output on demand.« This sounds more like Pavneet had a script to generate ConTeXt source from YAML input rather than ConTeXt itself typesetting YAML. – Henri Menke Aug 10 '16 at 8:20
  • 1
    Actually, it should be very easy to write your own YAML integration with ConTeXt. Just google Lua YAML parser. – Henri Menke Aug 10 '16 at 8:22
  • 1
    He posts regularly on the context mailing list. You can see his email address there or send a message to him on the mailing list to see what he meant exactly – Aditya Aug 10 '16 at 12:38
3

I have used lyaml to produce a useless minimal example (It is more a proof of concept).

I'm on Debian GNU/Linux where I installed the package lua-yaml. I had to symlink the files

/usr/share/lua/5.2/lyaml.lua
/usr/lib/x86_64-linux-gnu/lua/5.2/yaml.so

to the working directory, because ConTeXt only searchs /usr/local/... for me.

\startluacode
local lyaml = require "lyaml"

function parseyaml(buf)
    local input  = buffers.getcontent(buf)
    local struct = lyaml.load(input, { all = true })
    for _,section in pairs(struct) do
       context.startitemize()
       for title,element in pairs(section) do
          context.item(title)
          context.startitemize()
          for _,entry in pairs(element) do
             context.item(entry)
          end
          context.stopitemize()
       end
       context.stopitemize()
    end
end
\stopluacode

\startbuffer[grocery]
---
# A list of tasty fruits
fruits:
    - Apple
    - Orange
    - Strawberry
    - Mango
---
fruits: ['Apple', 'Orange', 'Strawberry', 'Mango']
...
\stopbuffer

\starttext

\startpacked
  \ctxlua{parseyaml("grocery")}  
\stoppacked

\stoptext

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.