How to avoid rewriting lines to generate code blocks The Next CEO of Stack OverflowHow to...

Is it ok to trim down a tube patch?

What CSS properties can the br tag have?

From jafe to El-Guest

Is it OK to decorate a log book cover?

Why am I getting "Static method cannot be referenced from a non static context: String String.valueOf(Object)"?

Do scriptures give a method to recognize a truly self-realized person/jivanmukta?

Reshaping json / reparing json inside shell script (remove trailing comma)

What flight has the highest ratio of timezone difference to flight time?

What was Carter Burke's job for "the company" in Aliens?

Is there an equivalent of cd - for cp or mv

Vector calculus integration identity problem

My ex-girlfriend uses my Apple ID to login to her iPad, do I have to give her my Apple ID password to reset it?

Which Pokemon have a special animation when running with them out of their pokeball?

Players Circumventing the limitations of Wish

IC has pull-down resistors on SMBus lines?

Help understanding this unsettling image of Titan, Epimetheus, and Saturn's rings?

"Eavesdropping" vs "Listen in on"

Does Germany produce more waste than the US?

What is the process for purifying your home if you believe it may have been previously used for pagan worship?

How to avoid supervisors with prejudiced views?

Are the names of these months realistic?

What connection does MS Office have to Netscape Navigator?

Is a distribution that is normal, but highly skewed, considered Gaussian?

What's the commands of Cisco query bgp neighbor table, bgp table and router table?



How to avoid rewriting lines to generate code blocks



The Next CEO of Stack OverflowHow to avoid duplication of longtable setup codeHow do I generate a check-list?How to avoid text style adoption in environment?How to avoid unwanted Spaces in NewDocumentEnvironment?How can I reduce the space around alltt environment blocks?How to define a new environment of two text blocks with number?Best way to insert source code blocks in an outline environmentHow insert a piece of code before and after environment?How to pass tikz code as an argument?How can I make these types of lines?












0















I have the following lines :



scriptsize
begin{Shaded}
lstset{language=C++,
keywordstyle=color{blue},
stringstyle=color{red},
commentstyle=color{green},
morecomment=[l][color{magenta}]{#}
}
begin{lstlisting}[frame=none]
int main(){
some_cpp_code
}
end{lstlisting}
end{Shaded}
normalsize


which I used to generate a block of c++ code lines. But this lines of latex codes should be repeated, because I need those blocks to be frequently used.



So what I would like to do is as follows:



First define a 'class-like' lines before the document.



Latex_class Code_block

scriptsize
begin{Shaded}
lstset{language=C++,
keywordstyle=color{blue},
stringstyle=color{red},
commentstyle=color{green},
morecomment=[l][color{magenta}]{#}
}
begin{lstlisting}[frame=none]
....
end{lstlisting}
end{Shaded}
normalsize


then use the class to avoid repetition of those lines:



begin{Code_block}
int main(){
some_cpp_code
}
end{Code_block}


But I'm wondering if there is any way to do so. Any help will be appreciated.









share







New contributor




Moreblue is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





















  • In which package is Shaded defined? Please add a compilable example.

    – JouleV
    2 mins ago
















0















I have the following lines :



scriptsize
begin{Shaded}
lstset{language=C++,
keywordstyle=color{blue},
stringstyle=color{red},
commentstyle=color{green},
morecomment=[l][color{magenta}]{#}
}
begin{lstlisting}[frame=none]
int main(){
some_cpp_code
}
end{lstlisting}
end{Shaded}
normalsize


which I used to generate a block of c++ code lines. But this lines of latex codes should be repeated, because I need those blocks to be frequently used.



So what I would like to do is as follows:



First define a 'class-like' lines before the document.



Latex_class Code_block

scriptsize
begin{Shaded}
lstset{language=C++,
keywordstyle=color{blue},
stringstyle=color{red},
commentstyle=color{green},
morecomment=[l][color{magenta}]{#}
}
begin{lstlisting}[frame=none]
....
end{lstlisting}
end{Shaded}
normalsize


then use the class to avoid repetition of those lines:



begin{Code_block}
int main(){
some_cpp_code
}
end{Code_block}


But I'm wondering if there is any way to do so. Any help will be appreciated.









share







New contributor




Moreblue is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





















  • In which package is Shaded defined? Please add a compilable example.

    – JouleV
    2 mins ago














0












0








0








I have the following lines :



scriptsize
begin{Shaded}
lstset{language=C++,
keywordstyle=color{blue},
stringstyle=color{red},
commentstyle=color{green},
morecomment=[l][color{magenta}]{#}
}
begin{lstlisting}[frame=none]
int main(){
some_cpp_code
}
end{lstlisting}
end{Shaded}
normalsize


which I used to generate a block of c++ code lines. But this lines of latex codes should be repeated, because I need those blocks to be frequently used.



So what I would like to do is as follows:



First define a 'class-like' lines before the document.



Latex_class Code_block

scriptsize
begin{Shaded}
lstset{language=C++,
keywordstyle=color{blue},
stringstyle=color{red},
commentstyle=color{green},
morecomment=[l][color{magenta}]{#}
}
begin{lstlisting}[frame=none]
....
end{lstlisting}
end{Shaded}
normalsize


then use the class to avoid repetition of those lines:



begin{Code_block}
int main(){
some_cpp_code
}
end{Code_block}


But I'm wondering if there is any way to do so. Any help will be appreciated.









share







New contributor




Moreblue is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












I have the following lines :



scriptsize
begin{Shaded}
lstset{language=C++,
keywordstyle=color{blue},
stringstyle=color{red},
commentstyle=color{green},
morecomment=[l][color{magenta}]{#}
}
begin{lstlisting}[frame=none]
int main(){
some_cpp_code
}
end{lstlisting}
end{Shaded}
normalsize


which I used to generate a block of c++ code lines. But this lines of latex codes should be repeated, because I need those blocks to be frequently used.



So what I would like to do is as follows:



First define a 'class-like' lines before the document.



Latex_class Code_block

scriptsize
begin{Shaded}
lstset{language=C++,
keywordstyle=color{blue},
stringstyle=color{red},
commentstyle=color{green},
morecomment=[l][color{magenta}]{#}
}
begin{lstlisting}[frame=none]
....
end{lstlisting}
end{Shaded}
normalsize


then use the class to avoid repetition of those lines:



begin{Code_block}
int main(){
some_cpp_code
}
end{Code_block}


But I'm wondering if there is any way to do so. Any help will be appreciated.







environments





share







New contributor




Moreblue is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.










share







New contributor




Moreblue is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.








share



share






New contributor




Moreblue is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 5 mins ago









MoreblueMoreblue

1013




1013




New contributor




Moreblue is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Moreblue is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Moreblue is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.













  • In which package is Shaded defined? Please add a compilable example.

    – JouleV
    2 mins ago



















  • In which package is Shaded defined? Please add a compilable example.

    – JouleV
    2 mins ago

















In which package is Shaded defined? Please add a compilable example.

– JouleV
2 mins ago





In which package is Shaded defined? Please add a compilable example.

– JouleV
2 mins ago










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
});


}
});






Moreblue is a new contributor. Be nice, and check out our Code of Conduct.










draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f482541%2fhow-to-avoid-rewriting-lines-to-generate-code-blocks%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








Moreblue is a new contributor. Be nice, and check out our Code of Conduct.










draft saved

draft discarded


















Moreblue is a new contributor. Be nice, and check out our Code of Conduct.













Moreblue is a new contributor. Be nice, and check out our Code of Conduct.












Moreblue 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.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f482541%2fhow-to-avoid-rewriting-lines-to-generate-code-blocks%23new-answer', 'question_page');
}
);

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







Popular posts from this blog

Can't compile dgruyter and caption packagesLaTeX templates/packages for writing a patent specificationLatex...

Schneeberg (Smreczany) Bibliografia | Menu...

Hans Bellmer Spis treści Życiorys | Upamiętnienie | Przypisy | Bibliografia | Linki zewnętrzne |...