Allow indentation of typing environments
Hi all, I'm having the following problem (or rather, inconvenience). When typing my ConTeX, I tend to properly indent all of my text, following the section headings. This makes my source a bit more readable. However, when I apply the same tactic to typing environments, all of the indentation is preserved in the output. This is of course to be expected, but it requires me to break the indentation for every typing environment, making very ugly source. Anyone else who also finds this problematic? What I'd like to see, is an option for a typing environment (say, stripindent) that makes the pretty printing code remove a fixed amount of indentation from every line. I've implemented this for some of my custom prettyprinters, but that's a lot of duplicate code, and it won't help others. Ideally, this would look at the indent of the \starttyping command and strip that much, but I don't think this is possible in TeX (or is it?) Slightly less ideal would be to look at all the lines, decide what the smallest indent is, and strip that. This would of course require buffering all the lines and start processing only when the final one is in, which is not very efficient given the current pretty printer implementation. What will probably work well enough is to look at the first line, and strip that much whitespace from all lines. This could be implemented entirely in lua. Would there be any interest for something like this? I could whip up a patch if there is. Where would be the logical place to do this? I don't see any need to let individiual pretty printers keep control over this, so I guess it is best handled before the pretty printers get at the line (So in buffers.typeline, probably. I guess inline \type commands don't need this, so this should work out). This also needs some initialization in buffers.type and buffers.typefile so we can detect what the first line is. Ideally, there would also be some sort of manual override, like: \starttyping[stripindent=4] but, I don't think any options are supported there currently (and adding them is very much over my head, since that would involve serious TeX coding...). To reach a conclusion, if I managed to implement this properly, would there be any interest for using this and including this in ConTeXt? Gr. Matthijs
On Thu, Nov 05 2009, Matthijs Kooijman wrote:
To reach a conclusion, if I managed to implement this properly, would there be any interest for using this and including this in ConTeXt?
Yes! See also: http://www.ntg.nl/pipermail/ntg-context/2008/033932.html Cheers, Peter -- Contact information: http://pmrb.free.fr/contact/
Matthijs Kooijman wrote:
Hi all,
I'm having the following problem (or rather, inconvenience). When typing my ConTeX, I tend to properly indent all of my text, following the section headings. This makes my source a bit more readable.
However, when I apply the same tactic to typing environments, all of the indentation is preserved in the output. This is of course to be expected, but it requires me to break the indentation for every typing environment, making very ugly source.
Anyone else who also finds this problematic?
What I'd like to see, is an option for a typing environment (say, stripindent) that makes the pretty printing code remove a fixed amount of indentation from every line.
I've implemented this for some of my custom prettyprinters, but that's a lot of duplicate code, and it won't help others.
Ideally, this would look at the indent of the \starttyping command and strip that much, but I don't think this is possible in TeX (or is it?)
Slightly less ideal would be to look at all the lines, decide what the smallest indent is, and strip that. This would of course require buffering all the lines and start processing only when the final one is in, which is not very efficient given the current pretty printer implementation.
What will probably work well enough is to look at the first line, and strip that much whitespace from all lines. This could be implemented entirely in lua. Would there be any interest for something like this? I could whip up a patch if there is.
Where would be the logical place to do this? I don't see any need to let individiual pretty printers keep control over this, so I guess it is best handled before the pretty printers get at the line (So in buffers.typeline, probably. I guess inline \type commands don't need this, so this should work out). This also needs some initialization in buffers.type and buffers.typefile so we can detect what the first line is.
Ideally, there would also be some sort of manual override, like:
\starttyping[stripindent=4]
but, I don't think any options are supported there currently (and adding them is very much over my head, since that would involve serious TeX coding...).
To reach a conclusion, if I managed to implement this properly, would there be any interest for using this and including this in ConTeXt?
This is not too complex to add ... (I cannot upload right now) add to the end of buff-ini.lua : function buffers.realign(name,forced_n) local d = data[name] if type(d) == "string" then d = d:splitlines() data[name] = d end local n for i=1, #d do local spaces = find(d[i],"%S") if not spaces then -- empty line elseif not n then n = spaces elseif spaces == 0 then n = 0 break elseif n > spaces then n = spaces end end if n > 0 then if forced_n and n > forced_n then -- we can also test for 'auto' n = forced_n end for i=1, #d do d[i] = sub(d[i],n,#d[i]) end end end and patch buff-ver.mkiv \unexpanded\def\dotypeblockverbatim#1#2% {\dowithbuffer{_typing_}{#1}{#2} {} {\doinitializeverbatim \beginofverbatimlines \ctxlua{buffers.realign("_typing_")}% % \ctxlua{buffers.realign("_typing_",3)}% \ctxlua{buffers.type("_typing_")}% \endofverbatimlines \csname#2\endcsname}} (needs a configuration option as well as to be hooked in elsewhere) a test like the following works ok test \starttyping test \stoptyping test \starttyping test \stoptyping test if all requests were so simple -) Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
On Thu, Nov 05 2009, Hans Hagen wrote:
add to the end of buff-ini.lua :
[...]
and patch buff-ver.mkiv
[...]
Hello Hans, Thanks a lot, this works very well! I attach a test file, that shows, that this works even in itemize environment and with the margin option. There are problems with the tabulation character, but's that's not so important.
if all requests were so simple -)
Perhaps there are other simple requests on http://tracker.luatex.org/ ... ;) This one can be closed now: http://tracker.luatex.org/view.php?id=118 Cheers, Peter -- Contact information: http://pmrb.free.fr/contact/
On Thu, 5 Nov 2009, Peter Münster wrote:
I attach a test file, that shows, that this works even in itemize environment and with the margin option. There are problems with the tabulation character, but's that's not so important.
This time, the file is really attached... Sorry, Peter -- Contact information: http://pmrb.free.fr/contact/
participants (3)
-
Hans Hagen
-
Matthijs Kooijman
-
Peter Münster