ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Wolfgang Schuster <wolfgang.schuster@gmail.com>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: Re: Getting the content of source lines in a \startlines \stoplines env?
Date: Mon, 4 Feb 2013 18:49:23 +0100	[thread overview]
Message-ID: <04D560BE-4CAA-4753-9D3E-887ED6D82AE8@gmail.com> (raw)
In-Reply-To: <510FEBD1.9000908@ingohohmann.de>


Am 04.02.2013 um 18:11 schrieb Ingo Hohmann <context@ingohohmann.de>:

> Hi,
> 
> in another thread I got an answer to the question, how to format lines in an environment automatically.
> Is there a way to get the content of source lines? For example, to save the line content into a variable?


You can save the content in a buffer and process the content with Lua.

\startluacode

userdata              = userdata              or { }
userdata.linescontent = userdata.linescontent or { }

local linescontent = userdata.linescontent

function linescontent.process()
	local lines = string.splitlines(buffers.getcontent("linescontent"))
	context.startlines()
	for i=1,#lines do
		local l = lines[i]
		if i == 1 then
			context("{\\bf %s}",l)
			context(true)
		elseif i == 2 then
			context("{\\tt %s}",l)
			context(true)
		else
			context("%s",l)
			context(true)
		end
	end
	context.stoplines()
end

\stopluacode

\def\startlinescontent
  {\grabbufferdata[linescontent][startlinescontent][stoplinescontent]}

\def\stoplinescontent
  {\ctxlua{userdata.linescontent.process()}}

\starttext

\startlinescontent
One
Two
Three
Four
Five
Six
\stoplinescontent

\stoptext

Wolfgang
___________________________________________________________________________________
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://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


  reply	other threads:[~2013-02-04 17:49 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-04 17:11 Ingo Hohmann
2013-02-04 17:49 ` Wolfgang Schuster [this message]
2013-02-04 18:05   ` Aditya Mahajan
2013-02-04 18:08     ` luigi scarso

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=04D560BE-4CAA-4753-9D3E-887ED6D82AE8@gmail.com \
    --to=wolfgang.schuster@gmail.com \
    --cc=ntg-context@ntg.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).