我将在这里编辑这个问题:
我希望能够\startc
像那样工作$$math$$
。
\starttext
In C, the program to print hello, world is
\startc
My C code here.
\stopc
Just how to run this program depends on the system you are using.
In C, the program to print hello, world is
$$
My C code here.
$$
Just how to run this program depends on the system you are using.
\stoptext
我希望能够\inlinec
像那样工作$math$
。
\starttext
This means that every program must have a \inlinec{main} somewhere.
\inlinec{main} will usually call other
This means that every program must have a \inlinec{main} somewhere.
$main$ will usually call other
\stoptext
编辑前的问题:
想要在 t-vim 代码块后面添加一个新段落。我通过{\ \vskip -1\baselineskip}
在代码块后面添加来实现这一点。但是它很脏。
在 ConTeXt 中执行此操作的正确方法是什么?
\parindent=20mm
\usemodule[vim]
\definevimtyping[c][margin=20mm]
\definevimtyping[sh][margin=20mm]
\starttext
In C, the program to print \quotation{\inlinesh{hello, world}} is
\startc
#include <stdio.h>
main()
{
printf("hello, world\n");
}
\stopc%{\ \vskip -1\baselineskip}%the paragraph should break here, but..
Just how to run this program depends on the system you are using.
\stoptext
答案1
实现所需行为的正确方法是indentnext=auto
。但是,模块中有一个错误,t-filter
导致indentnext=auto
无法正常工作。我上传了新版本t-filter
(版本:2018.08.10),并修复了错误。
对于内联代码,您看到的是因为\inlinec
发生在行首(如果{\bold Hello}
发生在行首,您将看到相同的行为)。可以通过使用\dontleavehmode
(或将left=\dontleavehmode
)作为选项来修复此问题definevimtyping
。我上传了新版本t-vim
(ver:2018.08.10),并修复了此错误。
为了完整起见,我在下面保留了我的旧答案。
旧答案
正确答案是indentnext=auto
,但由于回归错误,它不起作用。以下是适用于最小示例的快速修复。我将对其进行更多测试,然后发布t-filter
包含修复的新版本:
\usemodule[vim]
% THIS IS THE BUGFIX:
\unprotect
\starttexdefinition externalfilter@process_filter
% By defualt, buffers are in memory in MkIV. So, we save them to disk
%
% \savebuffer[\externalfilter@buffer_name][\externalfilter@input_file]
%
% We can also save a list of buffers to a file. The empty
% elements of the list are ignored. So, instead we use the following
%
% \savebuffer[\externalfilterparameter{\c!buffer\c!before},
% \externalfilter@buffer_name,
% \externalfilterparameter{\c!buffer\c!after}]
% [\externalfilter@input_file]}
%
% but using this method we cannot save the file in another directory.
% So, we use the key-value interface for \savebuffer.
\externalfilter@check_writable \externalfilter@input_file
\savebuffer
[
\c!list={\externalfilterparameter{\c!buffer\c!before},
\externalfilter@buffer_name,
\externalfilterparameter{\c!buffer\c!after}},
\c!file={\externalfilter@input_file},
\c!prefix=\v!no,
]
\externalfilter@execute_filter
\externalfilter@read_processed_file
\iftraceexternalfilters \else
\doif{\externalfilterparameter\c!purge}\v!yes
{\ctxlua{os.remove(\!!bs\externalfilter@input_file\!!es)}}
\fi
\endgroup % Moved before \dorechecknextindentation
% Finalization
\doifinset{\externalfilterparameter\c!cache}{\v!yes,\v!force}
{\doglobal\incrementvalue\externalfilter@count}
\doif{\externalfilterparameter\c!location}\v!paragraph
{\useindentnextparameter\externalfilterparameter
\dorechecknextindentation}
\stoptexdefinition
% Invisible space
\installspacemethod {\????syntaxhighlighting\v!off}
{\unexpanded\def\obeyedspace
{\mathortext\normalspace
{\syntaxhighlighting@split\interwordspace\relax}}%
\letcharcode\spaceasciicode\obeyedspace}
\保护 \保护
\definevimtyping[c][syntax=c,margin=20mm, indentnext=auto]
\setupindenting[20mm,yes]
\setupformula[indentnext=auto]
\starttext
In C, the program to print hello, world is
\startc
My C code here.
\stopc
Just how to run this program depends on the system you are using.
In C, the program to print hello, world is
\startformula
My C code here.
\stopformula
Just how to run this program depends on the system you are using.
This means that every program must have a \inlinec{main} somewhere.
\dontleavehmode\inlinec{main} will usually call other
This means that every program must have a \inlinec{main} somewhere.
$main$ will usually call other
\stoptext
上述示例还展示了如何使用内联代码修复此问题。基本上,当您以 开始新段落时,\inlinec
您需要在其前面加上\dontleavehmode
。您可以通过添加 来自动执行此left=\dontleavehmode
操作\definevimtyping
。
还有另外一个错误: 之前有一个多余的空格\inlinec
,上面的代码也修复了这个问题。
答案2
可以使用选项解决环境对缩进的抑制indentnext=yes
。以下内容似乎可以满足您的要求:
\setupindenting[20mm,yes]
\usemodule[vim]
\definevimtyping[c][margin=20mm,indentnext=yes]
\usemodule[vim]
\definevimtyping[c][margin=20mm]
\definevimtyping[sh][margin=20mm]
\starttext
In C, the program to print \quotation{\inlinesh{hello, world}} is
\startc
#include <stdio.h>
main()
{
printf("hello, world\n");
}
\stopc
Just how to run this program depends on the system you are using.
\stoptext
以供参考,这个问题似乎与缩进抑制有关。
更新:
评论中提到的$$...$$
公式块让我认为问题不仅仅在于缩进,还在于块上方和下方的间距。可以使用spacebefore
和spaceafter
选项修改此间距:
\setupindenting[20mm,yes]
\usemodule[vim]
\definevimtyping[c]
[margin=20mm,
indentnext=yes,
spacebefore=line,
spaceafter=line]
\usemodule[vim]
\definevimtyping[c][margin=20mm]
\definevimtyping[sh][margin=20mm]
\starttext
In C, the program to print \quotation{\inlinesh{hello, world}} is
\startc
#include <stdio.h>
main()
{
printf("hello, world\n");
}
\stopc
Just how to run this program depends on the system you are using.
\stoptext