Suppress line numbering for specific lines (including blank ones) in listings packageSuppress line numbering...
Confused by notation of atomic number Z and mass number A on periodic table of elements
Are Boeing 737-800’s grounded?
Has any spacecraft ever had the ability to directly communicate with civilian air traffic control?
What does YCWCYODFTRFDTY mean?
What's the metal clinking sound at the end of credits in Avengers: Endgame?
Does a creature that is immune to a condition still make a saving throw?
How to back up a running remote server?
What does "rf" mean in "rfkill"?
Did this character even qualify for being Azor Ahai or The One Who Was Promised?
Password expiration with Password manager
Is thermodynamics only applicable to systems in equilibrium?
Confusion about capacitors
Binary Numbers Magic Trick
How can I get precisely a certain cubic cm by changing the following factors?
Single Colour Mastermind Problem
amsmath: getting an error while using math mode to define piecewise function
How to create an ad-hoc wireless network in Ubuntu
Will tsunami waves travel forever if there was no land?
When and why did journal article titles become descriptive, rather than creatively allusive?
How to stop co-workers from teasing me because I know Russian?
List or Dictionary of Objects inside Class
Need help understanding harmonic series and intervals
I'm Syrian Citizen and i want to go to USA can someone help me please
Stark VS Thanos
Suppress line numbering for specific lines (including blank ones) in listings package
Suppress line numbering for specific lines in listings packageSuppress line numbering for empty lines in listings packageSuppress line numbering for specific lines in listings packageLine numbering using listings package starts at random numberContinue line numbers in listings package?Disable line numbering of specific linesDefining a centered shadowboxed listings environmentLine numbers for listings using program packageline numbering including blank (empty lines)Line numbering of listingsAlgorithm2e - Disabling line numbers for specific lines
My question is exactly the same as this one, but in my case some of the lines for which I would like to suppress line numbering are blank, and the accepted answer for that question produces an incorrect line count when there are blank lines between the suppress and reactivate (see screenshots below).
Note that my problem is not simply suppressing line numbers for blank lines, I know I can use numberblanklines=false
for that. My problem is suppressing line numbers for specific lines that happen to be blank.
Here's the code I'm using:
lstset{
basicstyle=tinyttfamily,
numbers=left,
showlines=true,
tabsize=2,
escapeinside=??
}
letorigthelstnumberthelstnumber
makeatletter
newcommand*Suppressnumber{%
lst@AddToHook{OnNewLine}{%
letthelstnumberrelax%
advancec@lstnumber-@nerelax%
}%
}
newcommand*Reactivatenumber{%
lst@AddToHook{OnNewLine}{%
letthelstnumberorigthelstnumber%
advancec@lstnumber@nerelax}%
}
makeatother
Example 1 (no problem)
begin{lstlisting}[
caption=Listing,
language=Scala,
frame=tlrb,
linewidth=textwidth,
xleftmargin=0.25textwidth,
xrightmargin=0.25textwidth
]
// No blank lines between suppress and
// reactivate commands, no problem
def fib(n: Int): Int = n match {
case 0 | 1 => n
case _ => {
val fibNMinusOne = fib(n - 1)?Suppressnumber?
?Reactivatenumber?
val fibNMinusTwo = fib(n - 2)
fibNMinusOne + fibNMinusTwo
}
}
end{lstlisting}
Result:
Example 2 (incorrect line count)
begin{lstlisting}[
caption=Listing,
language=Scala,
frame=tlrb,
linewidth=textwidth,
xleftmargin=0.25textwidth,
xrightmargin=0.25textwidth
]
// One blank line between suppress and
// reactivate commands, line count is incorrect
def fib(n: Int): Int = n match {
case 0 | 1 => n
case _ => {
val fibNMinusOne = fib(n - 1)?Suppressnumber?
?Reactivatenumber?
val fibNMinusTwo = fib(n - 2)
fibNMinusOne + fibNMinusTwo
}
}
end{lstlisting}
Result:
Example 3 (no problem)
begin{lstlisting}[
caption=Listing,
language=Scala,
frame=tlrb,
linewidth=textwidth,
xleftmargin=0.25textwidth,
xrightmargin=0.25textwidth
]
// Non-blank line between suppress and
// reactivate commands, no problem
def fib(n: Int): Int = n match {
case 0 | 1 => n
case _ => {
val fibNMinusOne = fib(n - 1)?Suppressnumber?
// Some comment, line is not blank anymore
?Reactivatenumber?
val fibNMinusTwo = fib(n - 2)
fibNMinusOne + fibNMinusTwo
}
}
end{lstlisting}
Result:
How can I suppress line numbers consistently for both blank and non-blank lines?
listings line-numbering
New contributor
add a comment |
My question is exactly the same as this one, but in my case some of the lines for which I would like to suppress line numbering are blank, and the accepted answer for that question produces an incorrect line count when there are blank lines between the suppress and reactivate (see screenshots below).
Note that my problem is not simply suppressing line numbers for blank lines, I know I can use numberblanklines=false
for that. My problem is suppressing line numbers for specific lines that happen to be blank.
Here's the code I'm using:
lstset{
basicstyle=tinyttfamily,
numbers=left,
showlines=true,
tabsize=2,
escapeinside=??
}
letorigthelstnumberthelstnumber
makeatletter
newcommand*Suppressnumber{%
lst@AddToHook{OnNewLine}{%
letthelstnumberrelax%
advancec@lstnumber-@nerelax%
}%
}
newcommand*Reactivatenumber{%
lst@AddToHook{OnNewLine}{%
letthelstnumberorigthelstnumber%
advancec@lstnumber@nerelax}%
}
makeatother
Example 1 (no problem)
begin{lstlisting}[
caption=Listing,
language=Scala,
frame=tlrb,
linewidth=textwidth,
xleftmargin=0.25textwidth,
xrightmargin=0.25textwidth
]
// No blank lines between suppress and
// reactivate commands, no problem
def fib(n: Int): Int = n match {
case 0 | 1 => n
case _ => {
val fibNMinusOne = fib(n - 1)?Suppressnumber?
?Reactivatenumber?
val fibNMinusTwo = fib(n - 2)
fibNMinusOne + fibNMinusTwo
}
}
end{lstlisting}
Result:
Example 2 (incorrect line count)
begin{lstlisting}[
caption=Listing,
language=Scala,
frame=tlrb,
linewidth=textwidth,
xleftmargin=0.25textwidth,
xrightmargin=0.25textwidth
]
// One blank line between suppress and
// reactivate commands, line count is incorrect
def fib(n: Int): Int = n match {
case 0 | 1 => n
case _ => {
val fibNMinusOne = fib(n - 1)?Suppressnumber?
?Reactivatenumber?
val fibNMinusTwo = fib(n - 2)
fibNMinusOne + fibNMinusTwo
}
}
end{lstlisting}
Result:
Example 3 (no problem)
begin{lstlisting}[
caption=Listing,
language=Scala,
frame=tlrb,
linewidth=textwidth,
xleftmargin=0.25textwidth,
xrightmargin=0.25textwidth
]
// Non-blank line between suppress and
// reactivate commands, no problem
def fib(n: Int): Int = n match {
case 0 | 1 => n
case _ => {
val fibNMinusOne = fib(n - 1)?Suppressnumber?
// Some comment, line is not blank anymore
?Reactivatenumber?
val fibNMinusTwo = fib(n - 2)
fibNMinusOne + fibNMinusTwo
}
}
end{lstlisting}
Result:
How can I suppress line numbers consistently for both blank and non-blank lines?
listings line-numbering
New contributor
add a comment |
My question is exactly the same as this one, but in my case some of the lines for which I would like to suppress line numbering are blank, and the accepted answer for that question produces an incorrect line count when there are blank lines between the suppress and reactivate (see screenshots below).
Note that my problem is not simply suppressing line numbers for blank lines, I know I can use numberblanklines=false
for that. My problem is suppressing line numbers for specific lines that happen to be blank.
Here's the code I'm using:
lstset{
basicstyle=tinyttfamily,
numbers=left,
showlines=true,
tabsize=2,
escapeinside=??
}
letorigthelstnumberthelstnumber
makeatletter
newcommand*Suppressnumber{%
lst@AddToHook{OnNewLine}{%
letthelstnumberrelax%
advancec@lstnumber-@nerelax%
}%
}
newcommand*Reactivatenumber{%
lst@AddToHook{OnNewLine}{%
letthelstnumberorigthelstnumber%
advancec@lstnumber@nerelax}%
}
makeatother
Example 1 (no problem)
begin{lstlisting}[
caption=Listing,
language=Scala,
frame=tlrb,
linewidth=textwidth,
xleftmargin=0.25textwidth,
xrightmargin=0.25textwidth
]
// No blank lines between suppress and
// reactivate commands, no problem
def fib(n: Int): Int = n match {
case 0 | 1 => n
case _ => {
val fibNMinusOne = fib(n - 1)?Suppressnumber?
?Reactivatenumber?
val fibNMinusTwo = fib(n - 2)
fibNMinusOne + fibNMinusTwo
}
}
end{lstlisting}
Result:
Example 2 (incorrect line count)
begin{lstlisting}[
caption=Listing,
language=Scala,
frame=tlrb,
linewidth=textwidth,
xleftmargin=0.25textwidth,
xrightmargin=0.25textwidth
]
// One blank line between suppress and
// reactivate commands, line count is incorrect
def fib(n: Int): Int = n match {
case 0 | 1 => n
case _ => {
val fibNMinusOne = fib(n - 1)?Suppressnumber?
?Reactivatenumber?
val fibNMinusTwo = fib(n - 2)
fibNMinusOne + fibNMinusTwo
}
}
end{lstlisting}
Result:
Example 3 (no problem)
begin{lstlisting}[
caption=Listing,
language=Scala,
frame=tlrb,
linewidth=textwidth,
xleftmargin=0.25textwidth,
xrightmargin=0.25textwidth
]
// Non-blank line between suppress and
// reactivate commands, no problem
def fib(n: Int): Int = n match {
case 0 | 1 => n
case _ => {
val fibNMinusOne = fib(n - 1)?Suppressnumber?
// Some comment, line is not blank anymore
?Reactivatenumber?
val fibNMinusTwo = fib(n - 2)
fibNMinusOne + fibNMinusTwo
}
}
end{lstlisting}
Result:
How can I suppress line numbers consistently for both blank and non-blank lines?
listings line-numbering
New contributor
My question is exactly the same as this one, but in my case some of the lines for which I would like to suppress line numbering are blank, and the accepted answer for that question produces an incorrect line count when there are blank lines between the suppress and reactivate (see screenshots below).
Note that my problem is not simply suppressing line numbers for blank lines, I know I can use numberblanklines=false
for that. My problem is suppressing line numbers for specific lines that happen to be blank.
Here's the code I'm using:
lstset{
basicstyle=tinyttfamily,
numbers=left,
showlines=true,
tabsize=2,
escapeinside=??
}
letorigthelstnumberthelstnumber
makeatletter
newcommand*Suppressnumber{%
lst@AddToHook{OnNewLine}{%
letthelstnumberrelax%
advancec@lstnumber-@nerelax%
}%
}
newcommand*Reactivatenumber{%
lst@AddToHook{OnNewLine}{%
letthelstnumberorigthelstnumber%
advancec@lstnumber@nerelax}%
}
makeatother
Example 1 (no problem)
begin{lstlisting}[
caption=Listing,
language=Scala,
frame=tlrb,
linewidth=textwidth,
xleftmargin=0.25textwidth,
xrightmargin=0.25textwidth
]
// No blank lines between suppress and
// reactivate commands, no problem
def fib(n: Int): Int = n match {
case 0 | 1 => n
case _ => {
val fibNMinusOne = fib(n - 1)?Suppressnumber?
?Reactivatenumber?
val fibNMinusTwo = fib(n - 2)
fibNMinusOne + fibNMinusTwo
}
}
end{lstlisting}
Result:
Example 2 (incorrect line count)
begin{lstlisting}[
caption=Listing,
language=Scala,
frame=tlrb,
linewidth=textwidth,
xleftmargin=0.25textwidth,
xrightmargin=0.25textwidth
]
// One blank line between suppress and
// reactivate commands, line count is incorrect
def fib(n: Int): Int = n match {
case 0 | 1 => n
case _ => {
val fibNMinusOne = fib(n - 1)?Suppressnumber?
?Reactivatenumber?
val fibNMinusTwo = fib(n - 2)
fibNMinusOne + fibNMinusTwo
}
}
end{lstlisting}
Result:
Example 3 (no problem)
begin{lstlisting}[
caption=Listing,
language=Scala,
frame=tlrb,
linewidth=textwidth,
xleftmargin=0.25textwidth,
xrightmargin=0.25textwidth
]
// Non-blank line between suppress and
// reactivate commands, no problem
def fib(n: Int): Int = n match {
case 0 | 1 => n
case _ => {
val fibNMinusOne = fib(n - 1)?Suppressnumber?
// Some comment, line is not blank anymore
?Reactivatenumber?
val fibNMinusTwo = fib(n - 2)
fibNMinusOne + fibNMinusTwo
}
}
end{lstlisting}
Result:
How can I suppress line numbers consistently for both blank and non-blank lines?
listings line-numbering
listings line-numbering
New contributor
New contributor
New contributor
asked 33 mins ago
NamefieNamefie
61
61
New contributor
New contributor
add a comment |
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "85"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Namefie is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f488193%2fsuppress-line-numbering-for-specific-lines-including-blank-ones-in-listings-pa%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Namefie is a new contributor. Be nice, and check out our Code of Conduct.
Namefie is a new contributor. Be nice, and check out our Code of Conduct.
Namefie is a new contributor. Be nice, and check out our Code of Conduct.
Namefie is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to TeX - LaTeX Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f488193%2fsuppress-line-numbering-for-specific-lines-including-blank-ones-in-listings-pa%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown