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

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

Can Sneak Attack be used when hitting with an improvised weapon?

If Nick Fury and Coulson already knew about aliens (Kree and Skrull) why did they wait until Thor's appearance to start making weapons?

How do I fit a non linear curve?

(How) Could a medieval fantasy world survive a magic-induced "nuclear winter"?

Is it OK to decorate a log book cover?

What difference does it make using sed with/without whitespaces?

Is it okay to majorly distort historical facts while writing a fiction story?

Is Nisuin Biblical or Rabbinic?

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

IC has pull-down resistors on SMBus lines?

Inductor and Capacitor in Parallel

What CSS properties can the br tag have?

Does higher Oxidation/ reduction potential translate to higher energy storage in battery?

Why don't programming languages automatically manage the synchronous/asynchronous problem?

How to use ReplaceAll on an expression that contains a rule

Can you teleport closer to a creature you are Frightened of?

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

TikZ: How to fill area with a special pattern?

Could a dragon use its wings to swim?

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?

Film where the government was corrupt with aliens, people sent to kill aliens are given rigged visors not showing the right aliens

Why is the US ranked as #45 in Press Freedom ratings, despite its extremely permissive free speech laws?

Why did early computer designers eschew integers?



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.





Edited



I used Shaded environment as follows



usepackage{color}
definecolor{shadecolor}{RGB}{248,248,248}
newenvironment{Shaded}{begin{snugshade}}{end{snugshade}}








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.
















  • 1





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

    – JouleV
    5 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.





Edited



I used Shaded environment as follows



usepackage{color}
definecolor{shadecolor}{RGB}{248,248,248}
newenvironment{Shaded}{begin{snugshade}}{end{snugshade}}








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.
















  • 1





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

    – JouleV
    5 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.





Edited



I used Shaded environment as follows



usepackage{color}
definecolor{shadecolor}{RGB}{248,248,248}
newenvironment{Shaded}{begin{snugshade}}{end{snugshade}}








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.





Edited



I used Shaded environment as follows



usepackage{color}
definecolor{shadecolor}{RGB}{248,248,248}
newenvironment{Shaded}{begin{snugshade}}{end{snugshade}}






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








edited 1 min ago







Moreblue













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








  • 1





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

    – JouleV
    5 mins ago














  • 1





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

    – JouleV
    5 mins ago








1




1





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

– JouleV
5 mins ago





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

– JouleV
5 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

Why does my Macbook overheat and use so much CPU and energy when on YouTube?Why do so many insist on using...

How to prevent page numbers from appearing on glossaries?How to remove a dot and a page number in the...

Puerta de Hutt Referencias Enlaces externos Menú de navegación15°58′00″S 5°42′00″O /...