Vim module - different settings for inline and block code
Hi, I need different settings for code in inline and block mode. See the following example: \usemodule [vim] \definetextbackground [C] [location=text] \definevimtyping [C] [syntax=c, before={\starttextbackground[C]}, after=\stoptextbackground, margin=2em] \starttext This is C: \inlineC{int foo();}. \blank \startC int foo(){ return 0; } \stopC \stoptext Inline code needs “location=text”, block code on the other hand needs “location=paragraph” as text background setting. Sure, I can create two environments “Cinline” and “Cblock”, but that feels clumsy. What's the proper way to set up different backgrounds for inline and block code? Marco
Am 16.01.2013 um 15:51 schrieb Marco Patzer
Hi,
I need different settings for code in inline and block mode. See the following example:
\usemodule [vim] \definetextbackground [C] [location=text] \definevimtyping [C] [syntax=c, before={\starttextbackground[C]}, after=\stoptextbackground, margin=2em]
\starttext
This is C: \inlineC{int foo();}. \blank \startC int foo(){ return 0; } \stopC
\stoptext
Inline code needs “location=text”, block code on the other hand needs “location=paragraph” as text background setting. Sure, I can create two environments “Cinline” and “Cblock”, but that feels clumsy.
What's the proper way to set up different backgrounds for inline and block code?
You can try this (untested): \definetextbackground[InlineBackground][location=text] \definetextbackground[DisplayBackground][location=paragraph] \definevimytping [C] […, before={\ifhmode\startInlineBackground\else\startDisplayBackground\fi}, after={\ifhmode\stopInlineBackground\else\stopDisplayBackground\fi}, …] You could also ask Aditya to use different keys for display (e.g. before/aftter) and inline (e.g. left/right) code blocks. Wolfgang
On 2013–01–16 Wolfgang Schuster wrote:
\definevimytping [C] […, before={\ifhmode\startInlineBackground\else\startDisplayBackground\fi}, after={\ifhmode\stopInlineBackground\else\stopDisplayBackground\fi}, …]
That's a good idea and it seems to work.
You could also ask Aditya to use different keys for display (e.g. before/aftter) and inline (e.g. left/right) code blocks.
That's not necessary. I think your solution is clean enough. Thanks Wolfgang. Marco
Am 16.01.2013 um 16:39 schrieb Marco Patzer
On 2013–01–16 Wolfgang Schuster wrote:
\definevimytping [C] […, before={\ifhmode\startInlineBackground\else\startDisplayBackground\fi}, after={\ifhmode\stopInlineBackground\else\stopDisplayBackground\fi}, …]
That's a good idea and it seems to work.
You could also ask Aditya to use different keys for display (e.g. before/aftter) and inline (e.g. left/right) code blocks.
That's not necessary. I think your solution is clean enough.
The test doesn’t work when you use \inlineC at the beginning of a paragraph because TeX it at this moment still in vertical mode and you have to add a \dontleavehmode to force horizontal mode. <example> \def\TestMode {\ifhmode \bold{Horizontal Mode}% \else \bold{Vertical Mode}% \fi} \starttext \TestMode\ Inline \TestMode \dontleavehmode\TestMode\ Inline \TestMode \stoptext </example> Wolfgang
On Wed, 16 Jan 2013, Wolfgang Schuster wrote:
You could also ask Aditya to use different keys for display (e.g. before/aftter) and inline (e.g. left/right) code blocks.
That's a nice suggestion. I have implemented it in the dev version of the filter module: https://github.com/adityam/filter/tree/dev but haven't tested it beyond a simple test case: https://github.com/adityam/filter/blob/dev/tests/25-before-left.tex I'll do more thorough tests and a proper release later. Aditya
participants (3)
-
Aditya Mahajan
-
Marco Patzer
-
Wolfgang Schuster