LaTeX newcommand with verbatim or listings : problem with `#` (hash key)












0















I'm trying to define a macro with newcommand using verbatim or listings environment. It seems that the hash key in #1 (standing for the argument) is escaped, due to verbatim and listings.



I'm new to macros, so I tried something simple : it works with begin{center} ... end{center}.



documentclass[a4paper,oneside,11pt]{report}
newcommand{script}[1]{
begin{center}
#1
end{center}
}
begin{document}
script{blabla}
blibli
end{document}


When I replace center with verbatim, I get this error :




File ended while scanning use of @xverbatim.




or lstlisting :




Text dropped after begin of listing




I didn't find anything on stackoverflow nor https://tex.stackexchange.com : what would you advise to use those environments in macros (newcommand or maybe newenvironment) ?



Thanks in advance










share|improve this question


















  • 1





    What is the aim here? Verbatim content cannot be passed as an argument to other macros.

    – Werner
    yesterday











  • I'd like 1) to paste scripts and code without having to escape characters 2) make a minipage or sthg else, maybe a box, to distinguish between code and normal text in the page.

    – vvffl
    yesterday











  • By "scripts of code" are you referring to the actual code? I would suggest writing your own environment based on listings.

    – Werner
    yesterday











  • I'm making a tutorial in which I use PHP, bash, Sparql. But I'd like to paste any text with special chars. What do you mean with > writing your own environment based on listings. ? Is there a simple manner to do so (haven't found yet)?

    – vvffl
    yesterday
















0















I'm trying to define a macro with newcommand using verbatim or listings environment. It seems that the hash key in #1 (standing for the argument) is escaped, due to verbatim and listings.



I'm new to macros, so I tried something simple : it works with begin{center} ... end{center}.



documentclass[a4paper,oneside,11pt]{report}
newcommand{script}[1]{
begin{center}
#1
end{center}
}
begin{document}
script{blabla}
blibli
end{document}


When I replace center with verbatim, I get this error :




File ended while scanning use of @xverbatim.




or lstlisting :




Text dropped after begin of listing




I didn't find anything on stackoverflow nor https://tex.stackexchange.com : what would you advise to use those environments in macros (newcommand or maybe newenvironment) ?



Thanks in advance










share|improve this question


















  • 1





    What is the aim here? Verbatim content cannot be passed as an argument to other macros.

    – Werner
    yesterday











  • I'd like 1) to paste scripts and code without having to escape characters 2) make a minipage or sthg else, maybe a box, to distinguish between code and normal text in the page.

    – vvffl
    yesterday











  • By "scripts of code" are you referring to the actual code? I would suggest writing your own environment based on listings.

    – Werner
    yesterday











  • I'm making a tutorial in which I use PHP, bash, Sparql. But I'd like to paste any text with special chars. What do you mean with > writing your own environment based on listings. ? Is there a simple manner to do so (haven't found yet)?

    – vvffl
    yesterday














0












0








0








I'm trying to define a macro with newcommand using verbatim or listings environment. It seems that the hash key in #1 (standing for the argument) is escaped, due to verbatim and listings.



I'm new to macros, so I tried something simple : it works with begin{center} ... end{center}.



documentclass[a4paper,oneside,11pt]{report}
newcommand{script}[1]{
begin{center}
#1
end{center}
}
begin{document}
script{blabla}
blibli
end{document}


When I replace center with verbatim, I get this error :




File ended while scanning use of @xverbatim.




or lstlisting :




Text dropped after begin of listing




I didn't find anything on stackoverflow nor https://tex.stackexchange.com : what would you advise to use those environments in macros (newcommand or maybe newenvironment) ?



Thanks in advance










share|improve this question














I'm trying to define a macro with newcommand using verbatim or listings environment. It seems that the hash key in #1 (standing for the argument) is escaped, due to verbatim and listings.



I'm new to macros, so I tried something simple : it works with begin{center} ... end{center}.



documentclass[a4paper,oneside,11pt]{report}
newcommand{script}[1]{
begin{center}
#1
end{center}
}
begin{document}
script{blabla}
blibli
end{document}


When I replace center with verbatim, I get this error :




File ended while scanning use of @xverbatim.




or lstlisting :




Text dropped after begin of listing




I didn't find anything on stackoverflow nor https://tex.stackexchange.com : what would you advise to use those environments in macros (newcommand or maybe newenvironment) ?



Thanks in advance







macros latex special-characters listings verbatim






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked yesterday









vvfflvvffl

437




437








  • 1





    What is the aim here? Verbatim content cannot be passed as an argument to other macros.

    – Werner
    yesterday











  • I'd like 1) to paste scripts and code without having to escape characters 2) make a minipage or sthg else, maybe a box, to distinguish between code and normal text in the page.

    – vvffl
    yesterday











  • By "scripts of code" are you referring to the actual code? I would suggest writing your own environment based on listings.

    – Werner
    yesterday











  • I'm making a tutorial in which I use PHP, bash, Sparql. But I'd like to paste any text with special chars. What do you mean with > writing your own environment based on listings. ? Is there a simple manner to do so (haven't found yet)?

    – vvffl
    yesterday














  • 1





    What is the aim here? Verbatim content cannot be passed as an argument to other macros.

    – Werner
    yesterday











  • I'd like 1) to paste scripts and code without having to escape characters 2) make a minipage or sthg else, maybe a box, to distinguish between code and normal text in the page.

    – vvffl
    yesterday











  • By "scripts of code" are you referring to the actual code? I would suggest writing your own environment based on listings.

    – Werner
    yesterday











  • I'm making a tutorial in which I use PHP, bash, Sparql. But I'd like to paste any text with special chars. What do you mean with > writing your own environment based on listings. ? Is there a simple manner to do so (haven't found yet)?

    – vvffl
    yesterday








1




1





What is the aim here? Verbatim content cannot be passed as an argument to other macros.

– Werner
yesterday





What is the aim here? Verbatim content cannot be passed as an argument to other macros.

– Werner
yesterday













I'd like 1) to paste scripts and code without having to escape characters 2) make a minipage or sthg else, maybe a box, to distinguish between code and normal text in the page.

– vvffl
yesterday





I'd like 1) to paste scripts and code without having to escape characters 2) make a minipage or sthg else, maybe a box, to distinguish between code and normal text in the page.

– vvffl
yesterday













By "scripts of code" are you referring to the actual code? I would suggest writing your own environment based on listings.

– Werner
yesterday





By "scripts of code" are you referring to the actual code? I would suggest writing your own environment based on listings.

– Werner
yesterday













I'm making a tutorial in which I use PHP, bash, Sparql. But I'd like to paste any text with special chars. What do you mean with > writing your own environment based on listings. ? Is there a simple manner to do so (haven't found yet)?

– vvffl
yesterday





I'm making a tutorial in which I use PHP, bash, Sparql. But I'd like to paste any text with special chars. What do you mean with > writing your own environment based on listings. ? Is there a simple manner to do so (haven't found yet)?

– vvffl
yesterday












2 Answers
2






active

oldest

votes


















2














Verbatim content is tricky. You have to ask yourself what the intent is. If it's printing code, then king of the hill would be listings. I'd suggest that and define your own environment for large chunks of code-specific output.



Here's an example:



enter image description here



documentclass{article}

usepackage{listings}

lstnewenvironment{code}[1]
{lstset{#1}}% Add/update settings locally
{}

lstset{% Global options
frame = single,
basicstyle = ttfamilysmall,
language = PHP
}

begin{document}

My first PHP ``Hello World'' page:

begin{code}
<html>
<head>
<title>PHP Test</title>
</head>
<body>
<?php echo '<p>Hello World</p>'; ?>
</body>
</html>
end{code}

When you write lstinline!<title>PHP Test</test>!, it sets the textit{title} of the page.

end{document}





share|improve this answer
























  • Thank you very much Werner, you convinced me to learn more about listings. Didn't know of lstinline. Could you just explain the syntax of {lstset{#1}} : does it mean I can add an option as argument?

    – vvffl
    19 hours ago






  • 1





    @vvffl: Yes. I defined code as an environment that can take an optional argument. So you can call (say) begin{code}[language = bash]...end{code} to switch the language. It would probably be ideal for you to define a style depending on the language (styles include colour and other formatting specifications).

    – Werner
    19 hours ago











  • Thanks, it's exactly what I thought (I have somewhere in my tex files an old paper where I used custom syntax color for xml, so I'm going to 'grep' that first). So macros aren't that difficult, but the syntax still looks weird for me.

    – vvffl
    19 hours ago






  • 1





    @vvffl: This is a common requirement, but it's not well-supported. See Viewer-independent copyable spaces at the beginning of a line? The fact that the output (in the resulting PDF) does not include the spaces, they aren't selectable for copy-and-paste. As such, indentation is not preserved. The intent of (La)TeX is to produce beautiful documents and therefore might not fully support the "reverse" where that content is copied/pasted elsewhere.

    – Werner
    19 hours ago






  • 1





    @vvffl: You can try Copy-pasting leading whitespace and blank lines in listings package (PDF), which uses accsupp.

    – Werner
    19 hours ago



















0














Found a workaround for verbatim with verb command, and using tilde as delimiter (if I want to use tilde inside the script I have to use textasciitilde):



documentclass{article}

newcommand{scr}[1]{
begin{minipage}{0.9textwidth}
fbox{
parbox{textwidth}{
verb~#1~ % <-- HERE
}
}
end{minipage}
}

begin{document}
scr{Some script code here...

here a tilde : textasciitilde
}
end{document}


But nothing for listings...





EDIT :
I've just noticed that this workaround doesn't keep the "automatic" character escaping, so it's not what I was looking for. I'd like to be able to paste code without escaping special chars.






share|improve this answer


























  • This does not work. Within a verbatim setting (either within the verbatim environment or verb) macros like textasciitilde are not expanded to their meaning since is changed to represent a character. As such, your output should contain textasciitilde, not ~.

    – Werner
    yesterday











  • Thanks for your reply. Actually it does work on my install... Don't know how nor why!

    – vvffl
    yesterday











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
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: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
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
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54251182%2flatex-newcommand-with-verbatim-or-listings-problem-with-hash-key%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









2














Verbatim content is tricky. You have to ask yourself what the intent is. If it's printing code, then king of the hill would be listings. I'd suggest that and define your own environment for large chunks of code-specific output.



Here's an example:



enter image description here



documentclass{article}

usepackage{listings}

lstnewenvironment{code}[1]
{lstset{#1}}% Add/update settings locally
{}

lstset{% Global options
frame = single,
basicstyle = ttfamilysmall,
language = PHP
}

begin{document}

My first PHP ``Hello World'' page:

begin{code}
<html>
<head>
<title>PHP Test</title>
</head>
<body>
<?php echo '<p>Hello World</p>'; ?>
</body>
</html>
end{code}

When you write lstinline!<title>PHP Test</test>!, it sets the textit{title} of the page.

end{document}





share|improve this answer
























  • Thank you very much Werner, you convinced me to learn more about listings. Didn't know of lstinline. Could you just explain the syntax of {lstset{#1}} : does it mean I can add an option as argument?

    – vvffl
    19 hours ago






  • 1





    @vvffl: Yes. I defined code as an environment that can take an optional argument. So you can call (say) begin{code}[language = bash]...end{code} to switch the language. It would probably be ideal for you to define a style depending on the language (styles include colour and other formatting specifications).

    – Werner
    19 hours ago











  • Thanks, it's exactly what I thought (I have somewhere in my tex files an old paper where I used custom syntax color for xml, so I'm going to 'grep' that first). So macros aren't that difficult, but the syntax still looks weird for me.

    – vvffl
    19 hours ago






  • 1





    @vvffl: This is a common requirement, but it's not well-supported. See Viewer-independent copyable spaces at the beginning of a line? The fact that the output (in the resulting PDF) does not include the spaces, they aren't selectable for copy-and-paste. As such, indentation is not preserved. The intent of (La)TeX is to produce beautiful documents and therefore might not fully support the "reverse" where that content is copied/pasted elsewhere.

    – Werner
    19 hours ago






  • 1





    @vvffl: You can try Copy-pasting leading whitespace and blank lines in listings package (PDF), which uses accsupp.

    – Werner
    19 hours ago
















2














Verbatim content is tricky. You have to ask yourself what the intent is. If it's printing code, then king of the hill would be listings. I'd suggest that and define your own environment for large chunks of code-specific output.



Here's an example:



enter image description here



documentclass{article}

usepackage{listings}

lstnewenvironment{code}[1]
{lstset{#1}}% Add/update settings locally
{}

lstset{% Global options
frame = single,
basicstyle = ttfamilysmall,
language = PHP
}

begin{document}

My first PHP ``Hello World'' page:

begin{code}
<html>
<head>
<title>PHP Test</title>
</head>
<body>
<?php echo '<p>Hello World</p>'; ?>
</body>
</html>
end{code}

When you write lstinline!<title>PHP Test</test>!, it sets the textit{title} of the page.

end{document}





share|improve this answer
























  • Thank you very much Werner, you convinced me to learn more about listings. Didn't know of lstinline. Could you just explain the syntax of {lstset{#1}} : does it mean I can add an option as argument?

    – vvffl
    19 hours ago






  • 1





    @vvffl: Yes. I defined code as an environment that can take an optional argument. So you can call (say) begin{code}[language = bash]...end{code} to switch the language. It would probably be ideal for you to define a style depending on the language (styles include colour and other formatting specifications).

    – Werner
    19 hours ago











  • Thanks, it's exactly what I thought (I have somewhere in my tex files an old paper where I used custom syntax color for xml, so I'm going to 'grep' that first). So macros aren't that difficult, but the syntax still looks weird for me.

    – vvffl
    19 hours ago






  • 1





    @vvffl: This is a common requirement, but it's not well-supported. See Viewer-independent copyable spaces at the beginning of a line? The fact that the output (in the resulting PDF) does not include the spaces, they aren't selectable for copy-and-paste. As such, indentation is not preserved. The intent of (La)TeX is to produce beautiful documents and therefore might not fully support the "reverse" where that content is copied/pasted elsewhere.

    – Werner
    19 hours ago






  • 1





    @vvffl: You can try Copy-pasting leading whitespace and blank lines in listings package (PDF), which uses accsupp.

    – Werner
    19 hours ago














2












2








2







Verbatim content is tricky. You have to ask yourself what the intent is. If it's printing code, then king of the hill would be listings. I'd suggest that and define your own environment for large chunks of code-specific output.



Here's an example:



enter image description here



documentclass{article}

usepackage{listings}

lstnewenvironment{code}[1]
{lstset{#1}}% Add/update settings locally
{}

lstset{% Global options
frame = single,
basicstyle = ttfamilysmall,
language = PHP
}

begin{document}

My first PHP ``Hello World'' page:

begin{code}
<html>
<head>
<title>PHP Test</title>
</head>
<body>
<?php echo '<p>Hello World</p>'; ?>
</body>
</html>
end{code}

When you write lstinline!<title>PHP Test</test>!, it sets the textit{title} of the page.

end{document}





share|improve this answer













Verbatim content is tricky. You have to ask yourself what the intent is. If it's printing code, then king of the hill would be listings. I'd suggest that and define your own environment for large chunks of code-specific output.



Here's an example:



enter image description here



documentclass{article}

usepackage{listings}

lstnewenvironment{code}[1]
{lstset{#1}}% Add/update settings locally
{}

lstset{% Global options
frame = single,
basicstyle = ttfamilysmall,
language = PHP
}

begin{document}

My first PHP ``Hello World'' page:

begin{code}
<html>
<head>
<title>PHP Test</title>
</head>
<body>
<?php echo '<p>Hello World</p>'; ?>
</body>
</html>
end{code}

When you write lstinline!<title>PHP Test</test>!, it sets the textit{title} of the page.

end{document}






share|improve this answer












share|improve this answer



share|improve this answer










answered 23 hours ago









WernerWerner

7,86142644




7,86142644













  • Thank you very much Werner, you convinced me to learn more about listings. Didn't know of lstinline. Could you just explain the syntax of {lstset{#1}} : does it mean I can add an option as argument?

    – vvffl
    19 hours ago






  • 1





    @vvffl: Yes. I defined code as an environment that can take an optional argument. So you can call (say) begin{code}[language = bash]...end{code} to switch the language. It would probably be ideal for you to define a style depending on the language (styles include colour and other formatting specifications).

    – Werner
    19 hours ago











  • Thanks, it's exactly what I thought (I have somewhere in my tex files an old paper where I used custom syntax color for xml, so I'm going to 'grep' that first). So macros aren't that difficult, but the syntax still looks weird for me.

    – vvffl
    19 hours ago






  • 1





    @vvffl: This is a common requirement, but it's not well-supported. See Viewer-independent copyable spaces at the beginning of a line? The fact that the output (in the resulting PDF) does not include the spaces, they aren't selectable for copy-and-paste. As such, indentation is not preserved. The intent of (La)TeX is to produce beautiful documents and therefore might not fully support the "reverse" where that content is copied/pasted elsewhere.

    – Werner
    19 hours ago






  • 1





    @vvffl: You can try Copy-pasting leading whitespace and blank lines in listings package (PDF), which uses accsupp.

    – Werner
    19 hours ago



















  • Thank you very much Werner, you convinced me to learn more about listings. Didn't know of lstinline. Could you just explain the syntax of {lstset{#1}} : does it mean I can add an option as argument?

    – vvffl
    19 hours ago






  • 1





    @vvffl: Yes. I defined code as an environment that can take an optional argument. So you can call (say) begin{code}[language = bash]...end{code} to switch the language. It would probably be ideal for you to define a style depending on the language (styles include colour and other formatting specifications).

    – Werner
    19 hours ago











  • Thanks, it's exactly what I thought (I have somewhere in my tex files an old paper where I used custom syntax color for xml, so I'm going to 'grep' that first). So macros aren't that difficult, but the syntax still looks weird for me.

    – vvffl
    19 hours ago






  • 1





    @vvffl: This is a common requirement, but it's not well-supported. See Viewer-independent copyable spaces at the beginning of a line? The fact that the output (in the resulting PDF) does not include the spaces, they aren't selectable for copy-and-paste. As such, indentation is not preserved. The intent of (La)TeX is to produce beautiful documents and therefore might not fully support the "reverse" where that content is copied/pasted elsewhere.

    – Werner
    19 hours ago






  • 1





    @vvffl: You can try Copy-pasting leading whitespace and blank lines in listings package (PDF), which uses accsupp.

    – Werner
    19 hours ago

















Thank you very much Werner, you convinced me to learn more about listings. Didn't know of lstinline. Could you just explain the syntax of {lstset{#1}} : does it mean I can add an option as argument?

– vvffl
19 hours ago





Thank you very much Werner, you convinced me to learn more about listings. Didn't know of lstinline. Could you just explain the syntax of {lstset{#1}} : does it mean I can add an option as argument?

– vvffl
19 hours ago




1




1





@vvffl: Yes. I defined code as an environment that can take an optional argument. So you can call (say) begin{code}[language = bash]...end{code} to switch the language. It would probably be ideal for you to define a style depending on the language (styles include colour and other formatting specifications).

– Werner
19 hours ago





@vvffl: Yes. I defined code as an environment that can take an optional argument. So you can call (say) begin{code}[language = bash]...end{code} to switch the language. It would probably be ideal for you to define a style depending on the language (styles include colour and other formatting specifications).

– Werner
19 hours ago













Thanks, it's exactly what I thought (I have somewhere in my tex files an old paper where I used custom syntax color for xml, so I'm going to 'grep' that first). So macros aren't that difficult, but the syntax still looks weird for me.

– vvffl
19 hours ago





Thanks, it's exactly what I thought (I have somewhere in my tex files an old paper where I used custom syntax color for xml, so I'm going to 'grep' that first). So macros aren't that difficult, but the syntax still looks weird for me.

– vvffl
19 hours ago




1




1





@vvffl: This is a common requirement, but it's not well-supported. See Viewer-independent copyable spaces at the beginning of a line? The fact that the output (in the resulting PDF) does not include the spaces, they aren't selectable for copy-and-paste. As such, indentation is not preserved. The intent of (La)TeX is to produce beautiful documents and therefore might not fully support the "reverse" where that content is copied/pasted elsewhere.

– Werner
19 hours ago





@vvffl: This is a common requirement, but it's not well-supported. See Viewer-independent copyable spaces at the beginning of a line? The fact that the output (in the resulting PDF) does not include the spaces, they aren't selectable for copy-and-paste. As such, indentation is not preserved. The intent of (La)TeX is to produce beautiful documents and therefore might not fully support the "reverse" where that content is copied/pasted elsewhere.

– Werner
19 hours ago




1




1





@vvffl: You can try Copy-pasting leading whitespace and blank lines in listings package (PDF), which uses accsupp.

– Werner
19 hours ago





@vvffl: You can try Copy-pasting leading whitespace and blank lines in listings package (PDF), which uses accsupp.

– Werner
19 hours ago













0














Found a workaround for verbatim with verb command, and using tilde as delimiter (if I want to use tilde inside the script I have to use textasciitilde):



documentclass{article}

newcommand{scr}[1]{
begin{minipage}{0.9textwidth}
fbox{
parbox{textwidth}{
verb~#1~ % <-- HERE
}
}
end{minipage}
}

begin{document}
scr{Some script code here...

here a tilde : textasciitilde
}
end{document}


But nothing for listings...





EDIT :
I've just noticed that this workaround doesn't keep the "automatic" character escaping, so it's not what I was looking for. I'd like to be able to paste code without escaping special chars.






share|improve this answer


























  • This does not work. Within a verbatim setting (either within the verbatim environment or verb) macros like textasciitilde are not expanded to their meaning since is changed to represent a character. As such, your output should contain textasciitilde, not ~.

    – Werner
    yesterday











  • Thanks for your reply. Actually it does work on my install... Don't know how nor why!

    – vvffl
    yesterday
















0














Found a workaround for verbatim with verb command, and using tilde as delimiter (if I want to use tilde inside the script I have to use textasciitilde):



documentclass{article}

newcommand{scr}[1]{
begin{minipage}{0.9textwidth}
fbox{
parbox{textwidth}{
verb~#1~ % <-- HERE
}
}
end{minipage}
}

begin{document}
scr{Some script code here...

here a tilde : textasciitilde
}
end{document}


But nothing for listings...





EDIT :
I've just noticed that this workaround doesn't keep the "automatic" character escaping, so it's not what I was looking for. I'd like to be able to paste code without escaping special chars.






share|improve this answer


























  • This does not work. Within a verbatim setting (either within the verbatim environment or verb) macros like textasciitilde are not expanded to their meaning since is changed to represent a character. As such, your output should contain textasciitilde, not ~.

    – Werner
    yesterday











  • Thanks for your reply. Actually it does work on my install... Don't know how nor why!

    – vvffl
    yesterday














0












0








0







Found a workaround for verbatim with verb command, and using tilde as delimiter (if I want to use tilde inside the script I have to use textasciitilde):



documentclass{article}

newcommand{scr}[1]{
begin{minipage}{0.9textwidth}
fbox{
parbox{textwidth}{
verb~#1~ % <-- HERE
}
}
end{minipage}
}

begin{document}
scr{Some script code here...

here a tilde : textasciitilde
}
end{document}


But nothing for listings...





EDIT :
I've just noticed that this workaround doesn't keep the "automatic" character escaping, so it's not what I was looking for. I'd like to be able to paste code without escaping special chars.






share|improve this answer















Found a workaround for verbatim with verb command, and using tilde as delimiter (if I want to use tilde inside the script I have to use textasciitilde):



documentclass{article}

newcommand{scr}[1]{
begin{minipage}{0.9textwidth}
fbox{
parbox{textwidth}{
verb~#1~ % <-- HERE
}
}
end{minipage}
}

begin{document}
scr{Some script code here...

here a tilde : textasciitilde
}
end{document}


But nothing for listings...





EDIT :
I've just noticed that this workaround doesn't keep the "automatic" character escaping, so it's not what I was looking for. I'd like to be able to paste code without escaping special chars.







share|improve this answer














share|improve this answer



share|improve this answer








edited yesterday

























answered yesterday









vvfflvvffl

437




437













  • This does not work. Within a verbatim setting (either within the verbatim environment or verb) macros like textasciitilde are not expanded to their meaning since is changed to represent a character. As such, your output should contain textasciitilde, not ~.

    – Werner
    yesterday











  • Thanks for your reply. Actually it does work on my install... Don't know how nor why!

    – vvffl
    yesterday



















  • This does not work. Within a verbatim setting (either within the verbatim environment or verb) macros like textasciitilde are not expanded to their meaning since is changed to represent a character. As such, your output should contain textasciitilde, not ~.

    – Werner
    yesterday











  • Thanks for your reply. Actually it does work on my install... Don't know how nor why!

    – vvffl
    yesterday

















This does not work. Within a verbatim setting (either within the verbatim environment or verb) macros like textasciitilde are not expanded to their meaning since is changed to represent a character. As such, your output should contain textasciitilde, not ~.

– Werner
yesterday





This does not work. Within a verbatim setting (either within the verbatim environment or verb) macros like textasciitilde are not expanded to their meaning since is changed to represent a character. As such, your output should contain textasciitilde, not ~.

– Werner
yesterday













Thanks for your reply. Actually it does work on my install... Don't know how nor why!

– vvffl
yesterday





Thanks for your reply. Actually it does work on my install... Don't know how nor why!

– vvffl
yesterday


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • 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%2fstackoverflow.com%2fquestions%2f54251182%2flatex-newcommand-with-verbatim-or-listings-problem-with-hash-key%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

Homophylophilia

Updating UILabel text programmatically using a function

Cloud Functions - OpenCV Videocapture Read method fails for larger files from cloud storage