Multiple listing styles with caption packageMultiple listings styles“Listing #” below listings without a...
How can I add custom success page
Is there any use for defining additional entity types in a SOQL FROM clause?
What is the command to reset a PC without deleting any files
Information to fellow intern about hiring?
aging parents with no investments
Landlord wants to switch my lease to a "Land contract" to "get back at the city"
Are objects structures and/or vice versa?
Email Account under attack (really) - anything I can do?
Why is the design of haulage companies so “special”?
Is a vector space a subspace of itself?
A poker game description that does not feel gimmicky
Pristine Bit Checking
Doomsday-clock for my fantasy planet
Extreme, but not acceptable situation and I can't start the work tomorrow morning
Can the Produce Flame cantrip be used to grapple, or as an unarmed strike, in the right circumstances?
Does a dangling wire really electrocute me if I'm standing in water?
How could a lack of term limits lead to a "dictatorship?"
Is there a familial term for apples and pears?
Could a US political party gain complete control over the government by removing checks & balances?
Where else does the Shulchan Aruch quote an authority by name?
Prime joint compound before latex paint?
Find the number of surjections from A to B.
What is the offset in a seaplane's hull?
Calculate Levenshtein distance between two strings in Python
Multiple listing styles with caption package
Multiple listings styles“Listing #” below listings without a captionCaption for a listingCenter caption in listingMultiple listings stylesCode caption with listing without title, only numberslist of figures and tables when there are no figures or tables?change caption of multiple listing styleslisting caption with a break lineHow to correctly align caption with code listingSpace between caption and listing
This question is mainly related to Multiple listings styles. If I have usepackage{caption}
definition in the head of file, list of custom listings disappear. How to make it work?
documentclass{article}
usepackage{regexpatch}% http://ctan.org/pkg/regexpatch
usepackage{listings}% http://ctan.org/pkg/listings
usepackage{caption}
makeatletter
% --------------------------------------- C++
newcommand{lstlistcplusplusname}{List of C++}
lst@UserCommandlstlistofcplusplus{bgroup
letcontentsnamelstlistcplusplusname
letlst@temp@starttoc def@starttoc##1{lst@temp{loc}}%
tableofcontents egroup}
lstnewenvironment{cplusplus}[1][]{%
renewcommand{lstlistingname}{C++ Code}%
xpatchcmd*{lst@MakeCaption}{lol}{loc}{}{}%
lstset{language=C++,#1}}
{}
% --------------------------------------- R
newcommand{lstlistrcodename}{List of R}
lst@UserCommandlstlistofrcode{bgroup
letcontentsnamelstlistrcodename
letlst@temp@starttoc def@starttoc##1{lst@temp{lor}}%
tableofcontents egroup}
lstnewenvironment{rcode}[1][]{%
renewcommand{lstlistingname}{R Code}%
xpatchcmd*{lst@MakeCaption}{lol}{lor}{}{}%
lstset{language=R,#1}}
{}
% --------------------------------------- Pseudocode
newcommand{lstlistpseudocodename}{List of Pseudocode}
lst@UserCommandlstlistofpseudocode{bgroup
letcontentsnamelstlistpseudocodename
letlst@temp@starttoc def@starttoc##1{lst@temp{lop}}%
tableofcontents egroup}
lstnewenvironment{pseudocode}[1][]{%
renewcommand{lstlistingname}{Pseudocode}%
xpatchcmd*{lst@MakeCaption}{lol}{lop}{}{}%
lstset{basicstyle=ttfamily,#1}}
{}
makeatother
begin{document}
lstlistofcplusplus
lstlistofrcode
lstlistofpseudocode
begin{cplusplus}[caption={Hello world}]
// 'Hello World!' program
#include <iostream>
int main()
{
std::cout << "Hello World!" << std::endl;
return 0;
}
end{cplusplus}
begin{rcode}[caption={Hello world}]
cat('Hello, world!n')
end{rcode}
begin{pseudocode}[caption={Hello world}]
print "Hello world"
end{pseudocode}
end{document}
table-of-contents captions listings naming
New contributor
add a comment |
This question is mainly related to Multiple listings styles. If I have usepackage{caption}
definition in the head of file, list of custom listings disappear. How to make it work?
documentclass{article}
usepackage{regexpatch}% http://ctan.org/pkg/regexpatch
usepackage{listings}% http://ctan.org/pkg/listings
usepackage{caption}
makeatletter
% --------------------------------------- C++
newcommand{lstlistcplusplusname}{List of C++}
lst@UserCommandlstlistofcplusplus{bgroup
letcontentsnamelstlistcplusplusname
letlst@temp@starttoc def@starttoc##1{lst@temp{loc}}%
tableofcontents egroup}
lstnewenvironment{cplusplus}[1][]{%
renewcommand{lstlistingname}{C++ Code}%
xpatchcmd*{lst@MakeCaption}{lol}{loc}{}{}%
lstset{language=C++,#1}}
{}
% --------------------------------------- R
newcommand{lstlistrcodename}{List of R}
lst@UserCommandlstlistofrcode{bgroup
letcontentsnamelstlistrcodename
letlst@temp@starttoc def@starttoc##1{lst@temp{lor}}%
tableofcontents egroup}
lstnewenvironment{rcode}[1][]{%
renewcommand{lstlistingname}{R Code}%
xpatchcmd*{lst@MakeCaption}{lol}{lor}{}{}%
lstset{language=R,#1}}
{}
% --------------------------------------- Pseudocode
newcommand{lstlistpseudocodename}{List of Pseudocode}
lst@UserCommandlstlistofpseudocode{bgroup
letcontentsnamelstlistpseudocodename
letlst@temp@starttoc def@starttoc##1{lst@temp{lop}}%
tableofcontents egroup}
lstnewenvironment{pseudocode}[1][]{%
renewcommand{lstlistingname}{Pseudocode}%
xpatchcmd*{lst@MakeCaption}{lol}{lop}{}{}%
lstset{basicstyle=ttfamily,#1}}
{}
makeatother
begin{document}
lstlistofcplusplus
lstlistofrcode
lstlistofpseudocode
begin{cplusplus}[caption={Hello world}]
// 'Hello World!' program
#include <iostream>
int main()
{
std::cout << "Hello World!" << std::endl;
return 0;
}
end{cplusplus}
begin{rcode}[caption={Hello world}]
cat('Hello, world!n')
end{rcode}
begin{pseudocode}[caption={Hello world}]
print "Hello world"
end{pseudocode}
end{document}
table-of-contents captions listings naming
New contributor
add a comment |
This question is mainly related to Multiple listings styles. If I have usepackage{caption}
definition in the head of file, list of custom listings disappear. How to make it work?
documentclass{article}
usepackage{regexpatch}% http://ctan.org/pkg/regexpatch
usepackage{listings}% http://ctan.org/pkg/listings
usepackage{caption}
makeatletter
% --------------------------------------- C++
newcommand{lstlistcplusplusname}{List of C++}
lst@UserCommandlstlistofcplusplus{bgroup
letcontentsnamelstlistcplusplusname
letlst@temp@starttoc def@starttoc##1{lst@temp{loc}}%
tableofcontents egroup}
lstnewenvironment{cplusplus}[1][]{%
renewcommand{lstlistingname}{C++ Code}%
xpatchcmd*{lst@MakeCaption}{lol}{loc}{}{}%
lstset{language=C++,#1}}
{}
% --------------------------------------- R
newcommand{lstlistrcodename}{List of R}
lst@UserCommandlstlistofrcode{bgroup
letcontentsnamelstlistrcodename
letlst@temp@starttoc def@starttoc##1{lst@temp{lor}}%
tableofcontents egroup}
lstnewenvironment{rcode}[1][]{%
renewcommand{lstlistingname}{R Code}%
xpatchcmd*{lst@MakeCaption}{lol}{lor}{}{}%
lstset{language=R,#1}}
{}
% --------------------------------------- Pseudocode
newcommand{lstlistpseudocodename}{List of Pseudocode}
lst@UserCommandlstlistofpseudocode{bgroup
letcontentsnamelstlistpseudocodename
letlst@temp@starttoc def@starttoc##1{lst@temp{lop}}%
tableofcontents egroup}
lstnewenvironment{pseudocode}[1][]{%
renewcommand{lstlistingname}{Pseudocode}%
xpatchcmd*{lst@MakeCaption}{lol}{lop}{}{}%
lstset{basicstyle=ttfamily,#1}}
{}
makeatother
begin{document}
lstlistofcplusplus
lstlistofrcode
lstlistofpseudocode
begin{cplusplus}[caption={Hello world}]
// 'Hello World!' program
#include <iostream>
int main()
{
std::cout << "Hello World!" << std::endl;
return 0;
}
end{cplusplus}
begin{rcode}[caption={Hello world}]
cat('Hello, world!n')
end{rcode}
begin{pseudocode}[caption={Hello world}]
print "Hello world"
end{pseudocode}
end{document}
table-of-contents captions listings naming
New contributor
This question is mainly related to Multiple listings styles. If I have usepackage{caption}
definition in the head of file, list of custom listings disappear. How to make it work?
documentclass{article}
usepackage{regexpatch}% http://ctan.org/pkg/regexpatch
usepackage{listings}% http://ctan.org/pkg/listings
usepackage{caption}
makeatletter
% --------------------------------------- C++
newcommand{lstlistcplusplusname}{List of C++}
lst@UserCommandlstlistofcplusplus{bgroup
letcontentsnamelstlistcplusplusname
letlst@temp@starttoc def@starttoc##1{lst@temp{loc}}%
tableofcontents egroup}
lstnewenvironment{cplusplus}[1][]{%
renewcommand{lstlistingname}{C++ Code}%
xpatchcmd*{lst@MakeCaption}{lol}{loc}{}{}%
lstset{language=C++,#1}}
{}
% --------------------------------------- R
newcommand{lstlistrcodename}{List of R}
lst@UserCommandlstlistofrcode{bgroup
letcontentsnamelstlistrcodename
letlst@temp@starttoc def@starttoc##1{lst@temp{lor}}%
tableofcontents egroup}
lstnewenvironment{rcode}[1][]{%
renewcommand{lstlistingname}{R Code}%
xpatchcmd*{lst@MakeCaption}{lol}{lor}{}{}%
lstset{language=R,#1}}
{}
% --------------------------------------- Pseudocode
newcommand{lstlistpseudocodename}{List of Pseudocode}
lst@UserCommandlstlistofpseudocode{bgroup
letcontentsnamelstlistpseudocodename
letlst@temp@starttoc def@starttoc##1{lst@temp{lop}}%
tableofcontents egroup}
lstnewenvironment{pseudocode}[1][]{%
renewcommand{lstlistingname}{Pseudocode}%
xpatchcmd*{lst@MakeCaption}{lol}{lop}{}{}%
lstset{basicstyle=ttfamily,#1}}
{}
makeatother
begin{document}
lstlistofcplusplus
lstlistofrcode
lstlistofpseudocode
begin{cplusplus}[caption={Hello world}]
// 'Hello World!' program
#include <iostream>
int main()
{
std::cout << "Hello World!" << std::endl;
return 0;
}
end{cplusplus}
begin{rcode}[caption={Hello world}]
cat('Hello, world!n')
end{rcode}
begin{pseudocode}[caption={Hello world}]
print "Hello world"
end{pseudocode}
end{document}
table-of-contents captions listings naming
table-of-contents captions listings naming
New contributor
New contributor
New contributor
asked 18 hours ago
SezenSezen
133
133
New contributor
New contributor
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
I don't know for sure, but I think ,there's a clash between the regexpatch
package and the caption
package. As an alternative to the caption
package, I found the capt-of
package in CTAN. When I used this package everything worked smoothly.
documentclass{article}
usepackage{regexpatch}% http://ctan.org/pkg/regexpatch
usepackage{listings}% http://ctan.org/pkg/listings
usepackage{capt-of}
usepackage{graphicx}
makeatletter
% --------------------------------------- C++
newcommand{lstlistcplusplusname}{List of C++}
lst@UserCommandlstlistofcplusplus{bgroup
letcontentsnamelstlistcplusplusname
letlst@temp@starttoc def@starttoc##1{lst@temp{loc}}%
tableofcontents egroup}
lstnewenvironment{cplusplus}[1][]{%
renewcommand{lstlistingname}{C++ Code}%
xpatchcmd*{lst@MakeCaption}{lol}{loc}{}{}%
lstset{language=C++,#1}}
{}
% --------------------------------------- R
newcommand{lstlistrcodename}{List of R}
lst@UserCommandlstlistofrcode{bgroup
letcontentsnamelstlistrcodename
letlst@temp@starttoc def@starttoc##1{lst@temp{lor}}%
tableofcontents egroup}
lstnewenvironment{rcode}[1][]{%
renewcommand{lstlistingname}{R Code}%
xpatchcmd*{lst@MakeCaption}{lol}{lor}{}{}%
lstset{language=R,#1}}
{}
% --------------------------------------- Pseudocode
newcommand{lstlistpseudocodename}{List of Pseudocode}
lst@UserCommandlstlistofpseudocode{bgroup
letcontentsnamelstlistpseudocodename
letlst@temp@starttoc def@starttoc##1{lst@temp{lop}}%
tableofcontents egroup}
lstnewenvironment{pseudocode}[1][]{%
renewcommand{lstlistingname}{Pseudocode}%
xpatchcmd*{lst@MakeCaption}{lol}{lop}{}{}%
lstset{basicstyle=ttfamily,#1}}
{}
makeatother
begin{document}
lstlistofcplusplus
lstlistofrcode
lstlistofpseudocode
begin{cplusplus}[caption={Hello world}]
// 'Hello World!' program
#include <iostream>
int main()
{
std::cout << "Hello World!" << std::endl;
return 0;
}
end{cplusplus}
begin{rcode}[caption={Hello world}]
cat('Hello, world!n')
end{rcode}
begin{pseudocode}[caption={Hello world}]
print "Hello world"
end{pseudocode}
begin{figure}[h]
centering
includegraphics[scale=0.5]{example-image-a}
captionof{figure}{Example image a.}
end{figure}
end{document}
Thanks for the answer butcaption
is widely used package and has a lot of methods likecaptionsetup
to change captions. I really would like to have a solution with caption package.
– Sezen
15 hours ago
It's not clear to me why do you think this is a clash betweenregexpatch
andcaption
.
– Axel Sommerfeldt
11 hours ago
As I said, it was just the assumption.
– ferahfeza
10 hours ago
add a comment |
The caption
package needs to patch lst@MakeCaption
to adapt the listings
package to the features of the caption
package. It stores (and uses) the original definition of lst@MakeCaption
into a macro called caption@ORI@lst@MakeCaption
, so to make your solution work, this macro needs to be patched:
documentclass{article}
usepackage{regexpatch}% http://ctan.org/pkg/regexpatch
usepackage{listings}% http://ctan.org/pkg/listings
usepackage{caption}
makeatletter
% --------------------------------------- C++
newcommand{lstlistcplusplusname}{List of C++}
lst@UserCommandlstlistofcplusplus{bgroup
letcontentsnamelstlistcplusplusname
letlst@temp@starttoc def@starttoc##1{lst@temp{loc}}%
tableofcontents egroup}
lstnewenvironment{cplusplus}[1][]{%
renewcommand{lstlistingname}{C++ Code}%
xpatchcmd*{lst@MakeCaption}{lol}{loc}{}{}%
xpatchcmd*{caption@ORI@lst@MakeCaption}{lol}{loc}{}{}%
lstset{language=C++,#1}}
{}
% --------------------------------------- R
newcommand{lstlistrcodename}{List of R}
lst@UserCommandlstlistofrcode{bgroup
letcontentsnamelstlistrcodename
letlst@temp@starttoc def@starttoc##1{lst@temp{lor}}%
tableofcontents egroup}
lstnewenvironment{rcode}[1][]{%
renewcommand{lstlistingname}{R Code}%
xpatchcmd*{lst@MakeCaption}{lol}{lor}{}{}%
xpatchcmd*{caption@ORI@lst@MakeCaption}{lol}{lor}{}{}%
lstset{language=R,#1}}
{}
% --------------------------------------- Pseudocode
newcommand{lstlistpseudocodename}{List of Pseudocode}
lst@UserCommandlstlistofpseudocode{bgroup
letcontentsnamelstlistpseudocodename
letlst@temp@starttoc def@starttoc##1{lst@temp{lop}}%
tableofcontents egroup}
lstnewenvironment{pseudocode}[1][]{%
renewcommand{lstlistingname}{Pseudocode}%
xpatchcmd*{lst@MakeCaption}{lol}{lop}{}{}%
xpatchcmd*{caption@ORI@lst@MakeCaption}{lol}{lop}{}{}%
lstset{basicstyle=ttfamily,#1}}
{}
makeatother
begin{document}
lstlistofcplusplus
lstlistofrcode
lstlistofpseudocode
begin{cplusplus}[caption={Hello world}]
// 'Hello World!' program
include
int main()
{
std::cout << "Hello World!" << std::endl;
return 0;
}
end{cplusplus}
begin{rcode}[caption={Hello world}]
cat('Hello, world!n')
end{rcode}
begin{pseudocode}[caption={Hello world}]
print "Hello world"
end{pseudocode}
end{document}
It's a pity that the listings
feature does not define and use defext@lstlisting{lol}
, like all other environments which do offer a "List of" feature. In this case redefining ext@lstlisting
would be sufficient, with and without caption
package (or any other package patching lst@MakeCaption
).
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',
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
});
}
});
Sezen 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%2f483775%2fmultiple-listing-styles-with-caption-package%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
I don't know for sure, but I think ,there's a clash between the regexpatch
package and the caption
package. As an alternative to the caption
package, I found the capt-of
package in CTAN. When I used this package everything worked smoothly.
documentclass{article}
usepackage{regexpatch}% http://ctan.org/pkg/regexpatch
usepackage{listings}% http://ctan.org/pkg/listings
usepackage{capt-of}
usepackage{graphicx}
makeatletter
% --------------------------------------- C++
newcommand{lstlistcplusplusname}{List of C++}
lst@UserCommandlstlistofcplusplus{bgroup
letcontentsnamelstlistcplusplusname
letlst@temp@starttoc def@starttoc##1{lst@temp{loc}}%
tableofcontents egroup}
lstnewenvironment{cplusplus}[1][]{%
renewcommand{lstlistingname}{C++ Code}%
xpatchcmd*{lst@MakeCaption}{lol}{loc}{}{}%
lstset{language=C++,#1}}
{}
% --------------------------------------- R
newcommand{lstlistrcodename}{List of R}
lst@UserCommandlstlistofrcode{bgroup
letcontentsnamelstlistrcodename
letlst@temp@starttoc def@starttoc##1{lst@temp{lor}}%
tableofcontents egroup}
lstnewenvironment{rcode}[1][]{%
renewcommand{lstlistingname}{R Code}%
xpatchcmd*{lst@MakeCaption}{lol}{lor}{}{}%
lstset{language=R,#1}}
{}
% --------------------------------------- Pseudocode
newcommand{lstlistpseudocodename}{List of Pseudocode}
lst@UserCommandlstlistofpseudocode{bgroup
letcontentsnamelstlistpseudocodename
letlst@temp@starttoc def@starttoc##1{lst@temp{lop}}%
tableofcontents egroup}
lstnewenvironment{pseudocode}[1][]{%
renewcommand{lstlistingname}{Pseudocode}%
xpatchcmd*{lst@MakeCaption}{lol}{lop}{}{}%
lstset{basicstyle=ttfamily,#1}}
{}
makeatother
begin{document}
lstlistofcplusplus
lstlistofrcode
lstlistofpseudocode
begin{cplusplus}[caption={Hello world}]
// 'Hello World!' program
#include <iostream>
int main()
{
std::cout << "Hello World!" << std::endl;
return 0;
}
end{cplusplus}
begin{rcode}[caption={Hello world}]
cat('Hello, world!n')
end{rcode}
begin{pseudocode}[caption={Hello world}]
print "Hello world"
end{pseudocode}
begin{figure}[h]
centering
includegraphics[scale=0.5]{example-image-a}
captionof{figure}{Example image a.}
end{figure}
end{document}
Thanks for the answer butcaption
is widely used package and has a lot of methods likecaptionsetup
to change captions. I really would like to have a solution with caption package.
– Sezen
15 hours ago
It's not clear to me why do you think this is a clash betweenregexpatch
andcaption
.
– Axel Sommerfeldt
11 hours ago
As I said, it was just the assumption.
– ferahfeza
10 hours ago
add a comment |
I don't know for sure, but I think ,there's a clash between the regexpatch
package and the caption
package. As an alternative to the caption
package, I found the capt-of
package in CTAN. When I used this package everything worked smoothly.
documentclass{article}
usepackage{regexpatch}% http://ctan.org/pkg/regexpatch
usepackage{listings}% http://ctan.org/pkg/listings
usepackage{capt-of}
usepackage{graphicx}
makeatletter
% --------------------------------------- C++
newcommand{lstlistcplusplusname}{List of C++}
lst@UserCommandlstlistofcplusplus{bgroup
letcontentsnamelstlistcplusplusname
letlst@temp@starttoc def@starttoc##1{lst@temp{loc}}%
tableofcontents egroup}
lstnewenvironment{cplusplus}[1][]{%
renewcommand{lstlistingname}{C++ Code}%
xpatchcmd*{lst@MakeCaption}{lol}{loc}{}{}%
lstset{language=C++,#1}}
{}
% --------------------------------------- R
newcommand{lstlistrcodename}{List of R}
lst@UserCommandlstlistofrcode{bgroup
letcontentsnamelstlistrcodename
letlst@temp@starttoc def@starttoc##1{lst@temp{lor}}%
tableofcontents egroup}
lstnewenvironment{rcode}[1][]{%
renewcommand{lstlistingname}{R Code}%
xpatchcmd*{lst@MakeCaption}{lol}{lor}{}{}%
lstset{language=R,#1}}
{}
% --------------------------------------- Pseudocode
newcommand{lstlistpseudocodename}{List of Pseudocode}
lst@UserCommandlstlistofpseudocode{bgroup
letcontentsnamelstlistpseudocodename
letlst@temp@starttoc def@starttoc##1{lst@temp{lop}}%
tableofcontents egroup}
lstnewenvironment{pseudocode}[1][]{%
renewcommand{lstlistingname}{Pseudocode}%
xpatchcmd*{lst@MakeCaption}{lol}{lop}{}{}%
lstset{basicstyle=ttfamily,#1}}
{}
makeatother
begin{document}
lstlistofcplusplus
lstlistofrcode
lstlistofpseudocode
begin{cplusplus}[caption={Hello world}]
// 'Hello World!' program
#include <iostream>
int main()
{
std::cout << "Hello World!" << std::endl;
return 0;
}
end{cplusplus}
begin{rcode}[caption={Hello world}]
cat('Hello, world!n')
end{rcode}
begin{pseudocode}[caption={Hello world}]
print "Hello world"
end{pseudocode}
begin{figure}[h]
centering
includegraphics[scale=0.5]{example-image-a}
captionof{figure}{Example image a.}
end{figure}
end{document}
Thanks for the answer butcaption
is widely used package and has a lot of methods likecaptionsetup
to change captions. I really would like to have a solution with caption package.
– Sezen
15 hours ago
It's not clear to me why do you think this is a clash betweenregexpatch
andcaption
.
– Axel Sommerfeldt
11 hours ago
As I said, it was just the assumption.
– ferahfeza
10 hours ago
add a comment |
I don't know for sure, but I think ,there's a clash between the regexpatch
package and the caption
package. As an alternative to the caption
package, I found the capt-of
package in CTAN. When I used this package everything worked smoothly.
documentclass{article}
usepackage{regexpatch}% http://ctan.org/pkg/regexpatch
usepackage{listings}% http://ctan.org/pkg/listings
usepackage{capt-of}
usepackage{graphicx}
makeatletter
% --------------------------------------- C++
newcommand{lstlistcplusplusname}{List of C++}
lst@UserCommandlstlistofcplusplus{bgroup
letcontentsnamelstlistcplusplusname
letlst@temp@starttoc def@starttoc##1{lst@temp{loc}}%
tableofcontents egroup}
lstnewenvironment{cplusplus}[1][]{%
renewcommand{lstlistingname}{C++ Code}%
xpatchcmd*{lst@MakeCaption}{lol}{loc}{}{}%
lstset{language=C++,#1}}
{}
% --------------------------------------- R
newcommand{lstlistrcodename}{List of R}
lst@UserCommandlstlistofrcode{bgroup
letcontentsnamelstlistrcodename
letlst@temp@starttoc def@starttoc##1{lst@temp{lor}}%
tableofcontents egroup}
lstnewenvironment{rcode}[1][]{%
renewcommand{lstlistingname}{R Code}%
xpatchcmd*{lst@MakeCaption}{lol}{lor}{}{}%
lstset{language=R,#1}}
{}
% --------------------------------------- Pseudocode
newcommand{lstlistpseudocodename}{List of Pseudocode}
lst@UserCommandlstlistofpseudocode{bgroup
letcontentsnamelstlistpseudocodename
letlst@temp@starttoc def@starttoc##1{lst@temp{lop}}%
tableofcontents egroup}
lstnewenvironment{pseudocode}[1][]{%
renewcommand{lstlistingname}{Pseudocode}%
xpatchcmd*{lst@MakeCaption}{lol}{lop}{}{}%
lstset{basicstyle=ttfamily,#1}}
{}
makeatother
begin{document}
lstlistofcplusplus
lstlistofrcode
lstlistofpseudocode
begin{cplusplus}[caption={Hello world}]
// 'Hello World!' program
#include <iostream>
int main()
{
std::cout << "Hello World!" << std::endl;
return 0;
}
end{cplusplus}
begin{rcode}[caption={Hello world}]
cat('Hello, world!n')
end{rcode}
begin{pseudocode}[caption={Hello world}]
print "Hello world"
end{pseudocode}
begin{figure}[h]
centering
includegraphics[scale=0.5]{example-image-a}
captionof{figure}{Example image a.}
end{figure}
end{document}
I don't know for sure, but I think ,there's a clash between the regexpatch
package and the caption
package. As an alternative to the caption
package, I found the capt-of
package in CTAN. When I used this package everything worked smoothly.
documentclass{article}
usepackage{regexpatch}% http://ctan.org/pkg/regexpatch
usepackage{listings}% http://ctan.org/pkg/listings
usepackage{capt-of}
usepackage{graphicx}
makeatletter
% --------------------------------------- C++
newcommand{lstlistcplusplusname}{List of C++}
lst@UserCommandlstlistofcplusplus{bgroup
letcontentsnamelstlistcplusplusname
letlst@temp@starttoc def@starttoc##1{lst@temp{loc}}%
tableofcontents egroup}
lstnewenvironment{cplusplus}[1][]{%
renewcommand{lstlistingname}{C++ Code}%
xpatchcmd*{lst@MakeCaption}{lol}{loc}{}{}%
lstset{language=C++,#1}}
{}
% --------------------------------------- R
newcommand{lstlistrcodename}{List of R}
lst@UserCommandlstlistofrcode{bgroup
letcontentsnamelstlistrcodename
letlst@temp@starttoc def@starttoc##1{lst@temp{lor}}%
tableofcontents egroup}
lstnewenvironment{rcode}[1][]{%
renewcommand{lstlistingname}{R Code}%
xpatchcmd*{lst@MakeCaption}{lol}{lor}{}{}%
lstset{language=R,#1}}
{}
% --------------------------------------- Pseudocode
newcommand{lstlistpseudocodename}{List of Pseudocode}
lst@UserCommandlstlistofpseudocode{bgroup
letcontentsnamelstlistpseudocodename
letlst@temp@starttoc def@starttoc##1{lst@temp{lop}}%
tableofcontents egroup}
lstnewenvironment{pseudocode}[1][]{%
renewcommand{lstlistingname}{Pseudocode}%
xpatchcmd*{lst@MakeCaption}{lol}{lop}{}{}%
lstset{basicstyle=ttfamily,#1}}
{}
makeatother
begin{document}
lstlistofcplusplus
lstlistofrcode
lstlistofpseudocode
begin{cplusplus}[caption={Hello world}]
// 'Hello World!' program
#include <iostream>
int main()
{
std::cout << "Hello World!" << std::endl;
return 0;
}
end{cplusplus}
begin{rcode}[caption={Hello world}]
cat('Hello, world!n')
end{rcode}
begin{pseudocode}[caption={Hello world}]
print "Hello world"
end{pseudocode}
begin{figure}[h]
centering
includegraphics[scale=0.5]{example-image-a}
captionof{figure}{Example image a.}
end{figure}
end{document}
edited 15 hours ago
answered 15 hours ago
ferahfezaferahfeza
7,41411933
7,41411933
Thanks for the answer butcaption
is widely used package and has a lot of methods likecaptionsetup
to change captions. I really would like to have a solution with caption package.
– Sezen
15 hours ago
It's not clear to me why do you think this is a clash betweenregexpatch
andcaption
.
– Axel Sommerfeldt
11 hours ago
As I said, it was just the assumption.
– ferahfeza
10 hours ago
add a comment |
Thanks for the answer butcaption
is widely used package and has a lot of methods likecaptionsetup
to change captions. I really would like to have a solution with caption package.
– Sezen
15 hours ago
It's not clear to me why do you think this is a clash betweenregexpatch
andcaption
.
– Axel Sommerfeldt
11 hours ago
As I said, it was just the assumption.
– ferahfeza
10 hours ago
Thanks for the answer but
caption
is widely used package and has a lot of methods like captionsetup
to change captions. I really would like to have a solution with caption package.– Sezen
15 hours ago
Thanks for the answer but
caption
is widely used package and has a lot of methods like captionsetup
to change captions. I really would like to have a solution with caption package.– Sezen
15 hours ago
It's not clear to me why do you think this is a clash between
regexpatch
and caption
.– Axel Sommerfeldt
11 hours ago
It's not clear to me why do you think this is a clash between
regexpatch
and caption
.– Axel Sommerfeldt
11 hours ago
As I said, it was just the assumption.
– ferahfeza
10 hours ago
As I said, it was just the assumption.
– ferahfeza
10 hours ago
add a comment |
The caption
package needs to patch lst@MakeCaption
to adapt the listings
package to the features of the caption
package. It stores (and uses) the original definition of lst@MakeCaption
into a macro called caption@ORI@lst@MakeCaption
, so to make your solution work, this macro needs to be patched:
documentclass{article}
usepackage{regexpatch}% http://ctan.org/pkg/regexpatch
usepackage{listings}% http://ctan.org/pkg/listings
usepackage{caption}
makeatletter
% --------------------------------------- C++
newcommand{lstlistcplusplusname}{List of C++}
lst@UserCommandlstlistofcplusplus{bgroup
letcontentsnamelstlistcplusplusname
letlst@temp@starttoc def@starttoc##1{lst@temp{loc}}%
tableofcontents egroup}
lstnewenvironment{cplusplus}[1][]{%
renewcommand{lstlistingname}{C++ Code}%
xpatchcmd*{lst@MakeCaption}{lol}{loc}{}{}%
xpatchcmd*{caption@ORI@lst@MakeCaption}{lol}{loc}{}{}%
lstset{language=C++,#1}}
{}
% --------------------------------------- R
newcommand{lstlistrcodename}{List of R}
lst@UserCommandlstlistofrcode{bgroup
letcontentsnamelstlistrcodename
letlst@temp@starttoc def@starttoc##1{lst@temp{lor}}%
tableofcontents egroup}
lstnewenvironment{rcode}[1][]{%
renewcommand{lstlistingname}{R Code}%
xpatchcmd*{lst@MakeCaption}{lol}{lor}{}{}%
xpatchcmd*{caption@ORI@lst@MakeCaption}{lol}{lor}{}{}%
lstset{language=R,#1}}
{}
% --------------------------------------- Pseudocode
newcommand{lstlistpseudocodename}{List of Pseudocode}
lst@UserCommandlstlistofpseudocode{bgroup
letcontentsnamelstlistpseudocodename
letlst@temp@starttoc def@starttoc##1{lst@temp{lop}}%
tableofcontents egroup}
lstnewenvironment{pseudocode}[1][]{%
renewcommand{lstlistingname}{Pseudocode}%
xpatchcmd*{lst@MakeCaption}{lol}{lop}{}{}%
xpatchcmd*{caption@ORI@lst@MakeCaption}{lol}{lop}{}{}%
lstset{basicstyle=ttfamily,#1}}
{}
makeatother
begin{document}
lstlistofcplusplus
lstlistofrcode
lstlistofpseudocode
begin{cplusplus}[caption={Hello world}]
// 'Hello World!' program
include
int main()
{
std::cout << "Hello World!" << std::endl;
return 0;
}
end{cplusplus}
begin{rcode}[caption={Hello world}]
cat('Hello, world!n')
end{rcode}
begin{pseudocode}[caption={Hello world}]
print "Hello world"
end{pseudocode}
end{document}
It's a pity that the listings
feature does not define and use defext@lstlisting{lol}
, like all other environments which do offer a "List of" feature. In this case redefining ext@lstlisting
would be sufficient, with and without caption
package (or any other package patching lst@MakeCaption
).
add a comment |
The caption
package needs to patch lst@MakeCaption
to adapt the listings
package to the features of the caption
package. It stores (and uses) the original definition of lst@MakeCaption
into a macro called caption@ORI@lst@MakeCaption
, so to make your solution work, this macro needs to be patched:
documentclass{article}
usepackage{regexpatch}% http://ctan.org/pkg/regexpatch
usepackage{listings}% http://ctan.org/pkg/listings
usepackage{caption}
makeatletter
% --------------------------------------- C++
newcommand{lstlistcplusplusname}{List of C++}
lst@UserCommandlstlistofcplusplus{bgroup
letcontentsnamelstlistcplusplusname
letlst@temp@starttoc def@starttoc##1{lst@temp{loc}}%
tableofcontents egroup}
lstnewenvironment{cplusplus}[1][]{%
renewcommand{lstlistingname}{C++ Code}%
xpatchcmd*{lst@MakeCaption}{lol}{loc}{}{}%
xpatchcmd*{caption@ORI@lst@MakeCaption}{lol}{loc}{}{}%
lstset{language=C++,#1}}
{}
% --------------------------------------- R
newcommand{lstlistrcodename}{List of R}
lst@UserCommandlstlistofrcode{bgroup
letcontentsnamelstlistrcodename
letlst@temp@starttoc def@starttoc##1{lst@temp{lor}}%
tableofcontents egroup}
lstnewenvironment{rcode}[1][]{%
renewcommand{lstlistingname}{R Code}%
xpatchcmd*{lst@MakeCaption}{lol}{lor}{}{}%
xpatchcmd*{caption@ORI@lst@MakeCaption}{lol}{lor}{}{}%
lstset{language=R,#1}}
{}
% --------------------------------------- Pseudocode
newcommand{lstlistpseudocodename}{List of Pseudocode}
lst@UserCommandlstlistofpseudocode{bgroup
letcontentsnamelstlistpseudocodename
letlst@temp@starttoc def@starttoc##1{lst@temp{lop}}%
tableofcontents egroup}
lstnewenvironment{pseudocode}[1][]{%
renewcommand{lstlistingname}{Pseudocode}%
xpatchcmd*{lst@MakeCaption}{lol}{lop}{}{}%
xpatchcmd*{caption@ORI@lst@MakeCaption}{lol}{lop}{}{}%
lstset{basicstyle=ttfamily,#1}}
{}
makeatother
begin{document}
lstlistofcplusplus
lstlistofrcode
lstlistofpseudocode
begin{cplusplus}[caption={Hello world}]
// 'Hello World!' program
include
int main()
{
std::cout << "Hello World!" << std::endl;
return 0;
}
end{cplusplus}
begin{rcode}[caption={Hello world}]
cat('Hello, world!n')
end{rcode}
begin{pseudocode}[caption={Hello world}]
print "Hello world"
end{pseudocode}
end{document}
It's a pity that the listings
feature does not define and use defext@lstlisting{lol}
, like all other environments which do offer a "List of" feature. In this case redefining ext@lstlisting
would be sufficient, with and without caption
package (or any other package patching lst@MakeCaption
).
add a comment |
The caption
package needs to patch lst@MakeCaption
to adapt the listings
package to the features of the caption
package. It stores (and uses) the original definition of lst@MakeCaption
into a macro called caption@ORI@lst@MakeCaption
, so to make your solution work, this macro needs to be patched:
documentclass{article}
usepackage{regexpatch}% http://ctan.org/pkg/regexpatch
usepackage{listings}% http://ctan.org/pkg/listings
usepackage{caption}
makeatletter
% --------------------------------------- C++
newcommand{lstlistcplusplusname}{List of C++}
lst@UserCommandlstlistofcplusplus{bgroup
letcontentsnamelstlistcplusplusname
letlst@temp@starttoc def@starttoc##1{lst@temp{loc}}%
tableofcontents egroup}
lstnewenvironment{cplusplus}[1][]{%
renewcommand{lstlistingname}{C++ Code}%
xpatchcmd*{lst@MakeCaption}{lol}{loc}{}{}%
xpatchcmd*{caption@ORI@lst@MakeCaption}{lol}{loc}{}{}%
lstset{language=C++,#1}}
{}
% --------------------------------------- R
newcommand{lstlistrcodename}{List of R}
lst@UserCommandlstlistofrcode{bgroup
letcontentsnamelstlistrcodename
letlst@temp@starttoc def@starttoc##1{lst@temp{lor}}%
tableofcontents egroup}
lstnewenvironment{rcode}[1][]{%
renewcommand{lstlistingname}{R Code}%
xpatchcmd*{lst@MakeCaption}{lol}{lor}{}{}%
xpatchcmd*{caption@ORI@lst@MakeCaption}{lol}{lor}{}{}%
lstset{language=R,#1}}
{}
% --------------------------------------- Pseudocode
newcommand{lstlistpseudocodename}{List of Pseudocode}
lst@UserCommandlstlistofpseudocode{bgroup
letcontentsnamelstlistpseudocodename
letlst@temp@starttoc def@starttoc##1{lst@temp{lop}}%
tableofcontents egroup}
lstnewenvironment{pseudocode}[1][]{%
renewcommand{lstlistingname}{Pseudocode}%
xpatchcmd*{lst@MakeCaption}{lol}{lop}{}{}%
xpatchcmd*{caption@ORI@lst@MakeCaption}{lol}{lop}{}{}%
lstset{basicstyle=ttfamily,#1}}
{}
makeatother
begin{document}
lstlistofcplusplus
lstlistofrcode
lstlistofpseudocode
begin{cplusplus}[caption={Hello world}]
// 'Hello World!' program
include
int main()
{
std::cout << "Hello World!" << std::endl;
return 0;
}
end{cplusplus}
begin{rcode}[caption={Hello world}]
cat('Hello, world!n')
end{rcode}
begin{pseudocode}[caption={Hello world}]
print "Hello world"
end{pseudocode}
end{document}
It's a pity that the listings
feature does not define and use defext@lstlisting{lol}
, like all other environments which do offer a "List of" feature. In this case redefining ext@lstlisting
would be sufficient, with and without caption
package (or any other package patching lst@MakeCaption
).
The caption
package needs to patch lst@MakeCaption
to adapt the listings
package to the features of the caption
package. It stores (and uses) the original definition of lst@MakeCaption
into a macro called caption@ORI@lst@MakeCaption
, so to make your solution work, this macro needs to be patched:
documentclass{article}
usepackage{regexpatch}% http://ctan.org/pkg/regexpatch
usepackage{listings}% http://ctan.org/pkg/listings
usepackage{caption}
makeatletter
% --------------------------------------- C++
newcommand{lstlistcplusplusname}{List of C++}
lst@UserCommandlstlistofcplusplus{bgroup
letcontentsnamelstlistcplusplusname
letlst@temp@starttoc def@starttoc##1{lst@temp{loc}}%
tableofcontents egroup}
lstnewenvironment{cplusplus}[1][]{%
renewcommand{lstlistingname}{C++ Code}%
xpatchcmd*{lst@MakeCaption}{lol}{loc}{}{}%
xpatchcmd*{caption@ORI@lst@MakeCaption}{lol}{loc}{}{}%
lstset{language=C++,#1}}
{}
% --------------------------------------- R
newcommand{lstlistrcodename}{List of R}
lst@UserCommandlstlistofrcode{bgroup
letcontentsnamelstlistrcodename
letlst@temp@starttoc def@starttoc##1{lst@temp{lor}}%
tableofcontents egroup}
lstnewenvironment{rcode}[1][]{%
renewcommand{lstlistingname}{R Code}%
xpatchcmd*{lst@MakeCaption}{lol}{lor}{}{}%
xpatchcmd*{caption@ORI@lst@MakeCaption}{lol}{lor}{}{}%
lstset{language=R,#1}}
{}
% --------------------------------------- Pseudocode
newcommand{lstlistpseudocodename}{List of Pseudocode}
lst@UserCommandlstlistofpseudocode{bgroup
letcontentsnamelstlistpseudocodename
letlst@temp@starttoc def@starttoc##1{lst@temp{lop}}%
tableofcontents egroup}
lstnewenvironment{pseudocode}[1][]{%
renewcommand{lstlistingname}{Pseudocode}%
xpatchcmd*{lst@MakeCaption}{lol}{lop}{}{}%
xpatchcmd*{caption@ORI@lst@MakeCaption}{lol}{lop}{}{}%
lstset{basicstyle=ttfamily,#1}}
{}
makeatother
begin{document}
lstlistofcplusplus
lstlistofrcode
lstlistofpseudocode
begin{cplusplus}[caption={Hello world}]
// 'Hello World!' program
include
int main()
{
std::cout << "Hello World!" << std::endl;
return 0;
}
end{cplusplus}
begin{rcode}[caption={Hello world}]
cat('Hello, world!n')
end{rcode}
begin{pseudocode}[caption={Hello world}]
print "Hello world"
end{pseudocode}
end{document}
It's a pity that the listings
feature does not define and use defext@lstlisting{lol}
, like all other environments which do offer a "List of" feature. In this case redefining ext@lstlisting
would be sufficient, with and without caption
package (or any other package patching lst@MakeCaption
).
answered 11 hours ago
Axel SommerfeldtAxel Sommerfeldt
12.2k22855
12.2k22855
add a comment |
add a comment |
Sezen is a new contributor. Be nice, and check out our Code of Conduct.
Sezen is a new contributor. Be nice, and check out our Code of Conduct.
Sezen is a new contributor. Be nice, and check out our Code of Conduct.
Sezen 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%2f483775%2fmultiple-listing-styles-with-caption-package%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