注释一行注释整个块

注释一行注释整个块

因此,我的文档中有段落,即使我尝试使用注释一行,%我也会发现该段落的其余部分也被注释了。我知道这一点,因为颜色变为灰色(使用 TeX Studio 2.5.2)。解决方案是什么?我认为我不需要该comment软件包。

答案1

问题下的所有评论都是正确的。TeXstudio 会换行超出查看窗口宽度的行。这允许您在一行中输入完整段落,并且在添加注释时,它将被视为一行。请查看下面的换行示例图。

您可以在 TeXstudio 中看到第一行太长,并且出现了换行符号。

我经常使用的一个解决方案是在段落中的每个句子后添加一个换行符,如下所示:

\documentclass[10pt,a4paper]{article}
\begin{document}
    Tractography refers to the three-dimensional modeling technique for visually display neural tracts.
    %
    The source data for tractography comes from diffusion tensor imaging (DTI) and magnetic resonance imaging (MRI).
    %
    By employing analysis techniques (including image analysis) on this source data, neural tracts can be identified throughout the brain.
    %
    These neural tracts are encoded as a series of line segments.


    Tractography is used for multiple purposes.
    %
    First, surgeons use tractography in conjunction with anatomical knowledge to plan surgeries around critical motor neurons for actions such as speech or movement. 
    %
    While this usage often does not require real-time analysis, the timelines between
    acquiring data and analysis by the surgeon is typically on the order of days.
    %
    Neuroscience researchers use tractography data in a different way: to create maps of the human brain.
    %
    In this case, the analysis has no real-time component, and analysis techniques taking longer periods are acceptable.
\end{document}

像这样编写文档可以很容易地添加、编辑或删除句子,并且不会导致您看到的评论问题。

选项 2 如果您不想像上面的例子那样重组段落而必须在适当位置对其进行注释,那么您可以定义一个注释命令:\newcommand{\comment}[1]{\ignorespaces}

这允许您注释块段落中的单个句子,同时%注释整个块的其余部分。请注意这些段落如何在一行中运行;这就是 TeXstudio 遇到的问题。

\documentclass[10pt,a4paper]{article}
\newcommand{\comment}[1]{\ignorespaces} % corrected!
\begin{document}    
    Tractography is used for multiple purposes.\comment{First, surgeons use tractography in conjunction with anatomical knowledge to plan surgeries around critical motor neurons for actions such as speech or movement.} While this usage often does not require real-time analysis, the timelines between acquiring data and analysis by the surgeon is typically on the order of days. Neuroscience researchers use tractography data in a different way: to create maps of the human brain. In this case, the analysis has no real-time component, and analysis techniques taking longer periods are acceptable.

    Tractography is used for multiple purposes. %First, surgeons use tractography in conjunction with anatomical knowledge to plan surgeries around critical motor neurons for actions such as speech or movement. While this usage often does not require real-time analysis, the timelines between acquiring data and analysis by the surgeon is typically on the order of days. Neuroscience researchers use tractography data in a different way: to create maps of the human brain. In this case, the analysis has no real-time component, and analysis techniques taking longer periods are acceptable.

\end{document}

选项 3 此选项将允许您在新的注释环境中突出显示注释样式。环境声明为:\newenvironment{hashed}[1]{\ignorespaces}{\ignorespacesafterend}

要在 TeXstudio 中启用高亮显示,请转到“选项->配置 Texstudio...”并将命令“hashed”添加到“自定义高亮显示”,并将“环境类型”设置为“注释”,如下所示: 在此处输入图片描述

它可以按如下方式使用(请注意注释样式突出显示): 在此处输入图片描述

这可能不是最干净的方法,但自定义环境是我所知道的向 TeXstudio 添加自定义突出显示的唯一方法。

答案2

正如@werner 已经建议的那样(在他对您的问题的评论中),您可以插入手动换行符(不留空行),这样您就可以注释掉常规段落中的特定行。

否则,您可以定义一个新的宏,它可以选择性地仅注释掉目标段落的特定行或部分,如果您使用此方法,您可以继续输入文本,而不必担心手动换行(当然,除非您想留下故意的换行符以在输出中开始新行,或者留下手动换行符后跟一个空白行以在输出中创建一个新段落)。

该宏可以定义为:

\newcommand{\hashed}[2]{#2}

或为:

\newcommand{\hashed}[1]{\ignorespaces}

我更喜欢前者而不是后者(没有任何特别的原因!只是我已经用了一段时间了)。将任一添加到文档前言(之前\begin{document}),然后就可以使用它了:

The Red dragon was mighty \& strong. \hashed{His scales were stronger than any steel man has ever known!} His name was Shruikan.

这两个命令的结果如下所示:

红龙威武而强壮。<space>他的名字叫 Shruikan。

正如我在上面对@cptnjtk 的解决方案的评论中提到的那样,如果这个宏是按照@cptnjtk 的建议定义的,即——

\newcommand{\hashed}[1]{}

上述结果将如下所示:

红龙威武而强壮。<space><space>他的名字叫 Shruikan。

为了避免插入这些额外的空格,请使用前面提到的任一宏。

相关内容