To "comment out" a line, I need to insert a %
at the beginning of the line (so that the line will not be compiled).
Is there a way to comment out a large section without having to manually place %
in front of each line?
comments
To "comment out" a line, I need to insert a %
at the beginning of the line (so that the line will not be compiled).
Is there a way to comment out a large section without having to manually place %
in front of each line?
If your input files all have the same form, that is some lines starting with \\
and an empty line after them, you can do by temporarily redefining \\
and changing the command for inputting the exercises:
\newcommand{\exeinput}[1]{%
\let\latexdoublebackslash\\
\ifprolog\let\\\showprolog\else\let\\\hideprolog\fi
\input{#1}}
\def\showprolog#1\par{%
\def\\{\par\noindent}% redefine `\\` to end lines
\par\noindent
#1% print the lines
\par % end the last line
\let\\\latexdoublebackslash}
\def\hideprolog#1\par{\let\\\latexdoublebackslash} % throw away the prolog lines
\newif\ifprolog
So you can say
\exeinput{exercise.435.tex}
and if you set \prologtrue
also the prolog lines will be printed.
However this would spectacularly fail if there's not an empty line between the prolog and the main contents, so a special markup is probably the best strategy. For instance, if your exercise files have the form
\startprolog
\\ is the exercise.435.tex % is the name of the file
\\ 1.84 ex. 127 page notes % is the source of exercise etc
\stopprolog
\begin{exercise}
. . .
\end{exercise}
you can say
\newif\ifprolog
\long\def\startprolog#1\stopprolog{%
\ifprolog
\par
\begingroup
\let\\\par
\color{red}\small #1
\par\medskip
\endgroup
\fi}
and so
\input{exercise.435.tex}
will print the exercise without the prolog unless you set \prologtrue
. The advantages are that you risk nothing if the prolog is not separated from the contents and that it's possible to reformat freely the prolog when you want to print it (maybe as a marginal note, for instance).
All of the comments under the question are correct. TeXstudio wraps lines that go beyond the width of the viewing window. This is what allows you to type a full paragraph on a single line, and when putting in comments, it is treated as a single line. Take a look at the line wrap example image below.
One solution I often use is to put a newline after every sentence in a paragraph as follows:
\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}
Writing documents like this makes it very easy to add, edit, or remove sentences, and does not cause the comment issue that you are seeing.
Option 2
If you do not want to restructure your paragraphs as in the above example and must comment them in place, you could define a comment command: \newcommand{\comment}[1]{\ignorespaces}
This allows you to comment a single sentence in a block paragraph, when %
would comment the entire remainder of the block. Notice how these paragraphs run off on one line; that is what was tripping TeXstudio up.
\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}
Option 3
This option will allow you to have comment style highlighting around the new comment environment. The environment declaration is: \newenvironment{hashed}[1]{\ignorespaces}{\ignorespacesafterend}
To enable hightlighting in TeXstudio go to "Options->Configure Texstudio..." and add the command "hashed" to "Custom Highlighting" and set the "Type of Environment" to "comment" as follows:
It can be used as follows (notice the comment style highlighting):
This may not be the cleanest method, but custom environemnts are the only way that I know to add custom highlighting to TeXstudio.
Best Answer
You can use
\iffalse ... \fi
to make (La)TeX not compile everything between it. However, this might not work properly if you have unmatched\ifxxx ... \fi
pairs inside them or do something else special with if-switches. It should be fine for normal user text.There is also the
comment
package which gives you thecomment
environment which ignores everything in it verbatim. It allows you to define own environments and to switch them on and off. You would use it by placing\usepackage{comment}
in the preamble. Below is an example: