Listings does not break at pure hyphen lines
up vote
3
down vote
favorite
I have the issue, that I need listings
package to break at a hyphen (-
). I will give a MWE below.
According to https://tex.stackexchange.com/a/140725/7166 the hyphen is a character of type "other", which should allow a line break if breakatwhitespace=false
(the default setting).
In my code to be typeset (included file generated by other software), long separation lines of pure hyphens are given. These seem not to break as expected.
Instead, only at the boundary letter/other character a possible linebreak might be done.
Adding allowbreak
as in https://tex.stackexchange.com/a/208254/7166 does not help.
Is this a bug in listings or am I missing some option?
documentclass[a4paper,10pt]{article}
usepackage[utf8]{inputenc}
usepackage{listings}
lstset{
basicstyle=ttfamilysmall,
breaklines=true,
frame=single
}
begin{document}
begin{lstlisting}
----------------------------------------------------a-------------------------------------------
-----------------------------------------------------------------------------------------------
end{lstlisting}
end{document}
listings line-breaking
add a comment |
up vote
3
down vote
favorite
I have the issue, that I need listings
package to break at a hyphen (-
). I will give a MWE below.
According to https://tex.stackexchange.com/a/140725/7166 the hyphen is a character of type "other", which should allow a line break if breakatwhitespace=false
(the default setting).
In my code to be typeset (included file generated by other software), long separation lines of pure hyphens are given. These seem not to break as expected.
Instead, only at the boundary letter/other character a possible linebreak might be done.
Adding allowbreak
as in https://tex.stackexchange.com/a/208254/7166 does not help.
Is this a bug in listings or am I missing some option?
documentclass[a4paper,10pt]{article}
usepackage[utf8]{inputenc}
usepackage{listings}
lstset{
basicstyle=ttfamilysmall,
breaklines=true,
frame=single
}
begin{document}
begin{lstlisting}
----------------------------------------------------a-------------------------------------------
-----------------------------------------------------------------------------------------------
end{lstlisting}
end{document}
listings line-breaking
1
listings
' tokenization mechanism is a bit more complicated, I think the exact rules aren't even mentioned in the user documentation but only in source code comments. However, addingliterate={-}{{-allowbreak}}{1}
, as proposed in the linked answer, fixes the problem for me.
– siracusa
Dec 7 at 16:46
Interesting.... When I pot theliterate=...
inside alstset{}
it works (also in my main document). When I put it in the optional agrument of thelstlisting
environment, this is no longer true.
– Christian Wolf
Dec 10 at 8:23
Strange, usingbegin{lstlisting}[literate={-}{{-allowbreak}}{1}]
in your above sample document works fine for me
– siracusa
Dec 10 at 9:16
1
Very strange. After playing around with this for some time now, I can no longer reproduce it. Either it was something in an update I just installed or I did not reach exactly the same code I tried with the optional argument. Maybe I was just dump. Thanks for helping anyways. Would you mind putting together a short answer, then I can accept?
– Christian Wolf
Dec 11 at 10:20
add a comment |
up vote
3
down vote
favorite
up vote
3
down vote
favorite
I have the issue, that I need listings
package to break at a hyphen (-
). I will give a MWE below.
According to https://tex.stackexchange.com/a/140725/7166 the hyphen is a character of type "other", which should allow a line break if breakatwhitespace=false
(the default setting).
In my code to be typeset (included file generated by other software), long separation lines of pure hyphens are given. These seem not to break as expected.
Instead, only at the boundary letter/other character a possible linebreak might be done.
Adding allowbreak
as in https://tex.stackexchange.com/a/208254/7166 does not help.
Is this a bug in listings or am I missing some option?
documentclass[a4paper,10pt]{article}
usepackage[utf8]{inputenc}
usepackage{listings}
lstset{
basicstyle=ttfamilysmall,
breaklines=true,
frame=single
}
begin{document}
begin{lstlisting}
----------------------------------------------------a-------------------------------------------
-----------------------------------------------------------------------------------------------
end{lstlisting}
end{document}
listings line-breaking
I have the issue, that I need listings
package to break at a hyphen (-
). I will give a MWE below.
According to https://tex.stackexchange.com/a/140725/7166 the hyphen is a character of type "other", which should allow a line break if breakatwhitespace=false
(the default setting).
In my code to be typeset (included file generated by other software), long separation lines of pure hyphens are given. These seem not to break as expected.
Instead, only at the boundary letter/other character a possible linebreak might be done.
Adding allowbreak
as in https://tex.stackexchange.com/a/208254/7166 does not help.
Is this a bug in listings or am I missing some option?
documentclass[a4paper,10pt]{article}
usepackage[utf8]{inputenc}
usepackage{listings}
lstset{
basicstyle=ttfamilysmall,
breaklines=true,
frame=single
}
begin{document}
begin{lstlisting}
----------------------------------------------------a-------------------------------------------
-----------------------------------------------------------------------------------------------
end{lstlisting}
end{document}
listings line-breaking
listings line-breaking
asked Dec 7 at 13:27
Christian Wolf
8531923
8531923
1
listings
' tokenization mechanism is a bit more complicated, I think the exact rules aren't even mentioned in the user documentation but only in source code comments. However, addingliterate={-}{{-allowbreak}}{1}
, as proposed in the linked answer, fixes the problem for me.
– siracusa
Dec 7 at 16:46
Interesting.... When I pot theliterate=...
inside alstset{}
it works (also in my main document). When I put it in the optional agrument of thelstlisting
environment, this is no longer true.
– Christian Wolf
Dec 10 at 8:23
Strange, usingbegin{lstlisting}[literate={-}{{-allowbreak}}{1}]
in your above sample document works fine for me
– siracusa
Dec 10 at 9:16
1
Very strange. After playing around with this for some time now, I can no longer reproduce it. Either it was something in an update I just installed or I did not reach exactly the same code I tried with the optional argument. Maybe I was just dump. Thanks for helping anyways. Would you mind putting together a short answer, then I can accept?
– Christian Wolf
Dec 11 at 10:20
add a comment |
1
listings
' tokenization mechanism is a bit more complicated, I think the exact rules aren't even mentioned in the user documentation but only in source code comments. However, addingliterate={-}{{-allowbreak}}{1}
, as proposed in the linked answer, fixes the problem for me.
– siracusa
Dec 7 at 16:46
Interesting.... When I pot theliterate=...
inside alstset{}
it works (also in my main document). When I put it in the optional agrument of thelstlisting
environment, this is no longer true.
– Christian Wolf
Dec 10 at 8:23
Strange, usingbegin{lstlisting}[literate={-}{{-allowbreak}}{1}]
in your above sample document works fine for me
– siracusa
Dec 10 at 9:16
1
Very strange. After playing around with this for some time now, I can no longer reproduce it. Either it was something in an update I just installed or I did not reach exactly the same code I tried with the optional argument. Maybe I was just dump. Thanks for helping anyways. Would you mind putting together a short answer, then I can accept?
– Christian Wolf
Dec 11 at 10:20
1
1
listings
' tokenization mechanism is a bit more complicated, I think the exact rules aren't even mentioned in the user documentation but only in source code comments. However, adding literate={-}{{-allowbreak}}{1}
, as proposed in the linked answer, fixes the problem for me.– siracusa
Dec 7 at 16:46
listings
' tokenization mechanism is a bit more complicated, I think the exact rules aren't even mentioned in the user documentation but only in source code comments. However, adding literate={-}{{-allowbreak}}{1}
, as proposed in the linked answer, fixes the problem for me.– siracusa
Dec 7 at 16:46
Interesting.... When I pot the
literate=...
inside a lstset{}
it works (also in my main document). When I put it in the optional agrument of the lstlisting
environment, this is no longer true.– Christian Wolf
Dec 10 at 8:23
Interesting.... When I pot the
literate=...
inside a lstset{}
it works (also in my main document). When I put it in the optional agrument of the lstlisting
environment, this is no longer true.– Christian Wolf
Dec 10 at 8:23
Strange, using
begin{lstlisting}[literate={-}{{-allowbreak}}{1}]
in your above sample document works fine for me– siracusa
Dec 10 at 9:16
Strange, using
begin{lstlisting}[literate={-}{{-allowbreak}}{1}]
in your above sample document works fine for me– siracusa
Dec 10 at 9:16
1
1
Very strange. After playing around with this for some time now, I can no longer reproduce it. Either it was something in an update I just installed or I did not reach exactly the same code I tried with the optional argument. Maybe I was just dump. Thanks for helping anyways. Would you mind putting together a short answer, then I can accept?
– Christian Wolf
Dec 11 at 10:20
Very strange. After playing around with this for some time now, I can no longer reproduce it. Either it was something in an update I just installed or I did not reach exactly the same code I tried with the optional argument. Maybe I was just dump. Thanks for helping anyways. Would you mind putting together a short answer, then I can accept?
– Christian Wolf
Dec 11 at 10:20
add a comment |
1 Answer
1
active
oldest
votes
up vote
2
down vote
accepted
Using the literate
option to allow breaks after -
works in your example. Make sure to have the latest version of the listings
package installed. You can set the option globally with
lstset{literate={-}{{-allowbreak}}{1}}
or selectively for single listings with
begin{lstlisting}[literate={-}{{-allowbreak}}{1}]
A word on why breaking doesn't work here by default. Section 9.5 of the extended listings
documentation describes how character sequences are built:
How do these 'classes' work together? Let's say that the current character string is
tr
. Then lettery
simply appends the letter and we gettry
. The next nonletter (and nondigit) causes the output of the characters. Then we collect all coming nonletters until reaching a letter again. This causes the output of the nonletters, and so on.
That means all the hyphen characters are glued together into a single, token-like sequence and are not broken at the end of the line, unless you use the literate
option to explicitly allow breaks inside it.
add a comment |
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',
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
});
}
});
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%2f463693%2flistings-does-not-break-at-pure-hyphen-lines%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
Using the literate
option to allow breaks after -
works in your example. Make sure to have the latest version of the listings
package installed. You can set the option globally with
lstset{literate={-}{{-allowbreak}}{1}}
or selectively for single listings with
begin{lstlisting}[literate={-}{{-allowbreak}}{1}]
A word on why breaking doesn't work here by default. Section 9.5 of the extended listings
documentation describes how character sequences are built:
How do these 'classes' work together? Let's say that the current character string is
tr
. Then lettery
simply appends the letter and we gettry
. The next nonletter (and nondigit) causes the output of the characters. Then we collect all coming nonletters until reaching a letter again. This causes the output of the nonletters, and so on.
That means all the hyphen characters are glued together into a single, token-like sequence and are not broken at the end of the line, unless you use the literate
option to explicitly allow breaks inside it.
add a comment |
up vote
2
down vote
accepted
Using the literate
option to allow breaks after -
works in your example. Make sure to have the latest version of the listings
package installed. You can set the option globally with
lstset{literate={-}{{-allowbreak}}{1}}
or selectively for single listings with
begin{lstlisting}[literate={-}{{-allowbreak}}{1}]
A word on why breaking doesn't work here by default. Section 9.5 of the extended listings
documentation describes how character sequences are built:
How do these 'classes' work together? Let's say that the current character string is
tr
. Then lettery
simply appends the letter and we gettry
. The next nonletter (and nondigit) causes the output of the characters. Then we collect all coming nonletters until reaching a letter again. This causes the output of the nonletters, and so on.
That means all the hyphen characters are glued together into a single, token-like sequence and are not broken at the end of the line, unless you use the literate
option to explicitly allow breaks inside it.
add a comment |
up vote
2
down vote
accepted
up vote
2
down vote
accepted
Using the literate
option to allow breaks after -
works in your example. Make sure to have the latest version of the listings
package installed. You can set the option globally with
lstset{literate={-}{{-allowbreak}}{1}}
or selectively for single listings with
begin{lstlisting}[literate={-}{{-allowbreak}}{1}]
A word on why breaking doesn't work here by default. Section 9.5 of the extended listings
documentation describes how character sequences are built:
How do these 'classes' work together? Let's say that the current character string is
tr
. Then lettery
simply appends the letter and we gettry
. The next nonletter (and nondigit) causes the output of the characters. Then we collect all coming nonletters until reaching a letter again. This causes the output of the nonletters, and so on.
That means all the hyphen characters are glued together into a single, token-like sequence and are not broken at the end of the line, unless you use the literate
option to explicitly allow breaks inside it.
Using the literate
option to allow breaks after -
works in your example. Make sure to have the latest version of the listings
package installed. You can set the option globally with
lstset{literate={-}{{-allowbreak}}{1}}
or selectively for single listings with
begin{lstlisting}[literate={-}{{-allowbreak}}{1}]
A word on why breaking doesn't work here by default. Section 9.5 of the extended listings
documentation describes how character sequences are built:
How do these 'classes' work together? Let's say that the current character string is
tr
. Then lettery
simply appends the letter and we gettry
. The next nonletter (and nondigit) causes the output of the characters. Then we collect all coming nonletters until reaching a letter again. This causes the output of the nonletters, and so on.
That means all the hyphen characters are glued together into a single, token-like sequence and are not broken at the end of the line, unless you use the literate
option to explicitly allow breaks inside it.
answered Dec 11 at 12:00
siracusa
4,92511228
4,92511228
add a comment |
add a comment |
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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%2f463693%2flistings-does-not-break-at-pure-hyphen-lines%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
1
listings
' tokenization mechanism is a bit more complicated, I think the exact rules aren't even mentioned in the user documentation but only in source code comments. However, addingliterate={-}{{-allowbreak}}{1}
, as proposed in the linked answer, fixes the problem for me.– siracusa
Dec 7 at 16:46
Interesting.... When I pot the
literate=...
inside alstset{}
it works (also in my main document). When I put it in the optional agrument of thelstlisting
environment, this is no longer true.– Christian Wolf
Dec 10 at 8:23
Strange, using
begin{lstlisting}[literate={-}{{-allowbreak}}{1}]
in your above sample document works fine for me– siracusa
Dec 10 at 9:16
1
Very strange. After playing around with this for some time now, I can no longer reproduce it. Either it was something in an update I just installed or I did not reach exactly the same code I tried with the optional argument. Maybe I was just dump. Thanks for helping anyways. Would you mind putting together a short answer, then I can accept?
– Christian Wolf
Dec 11 at 10:20