If \@percentchar represents %, is there a macro for #? I have tried \@sharpchar and \@numberchar but both do not exist. Do you have any idea what is the correct macro name for #?
- 36,086
2 Answers
To typeset # you can use \# but to have a macro that expands to a catcode 12 (normal character) # use \zzz defined by
\edef\zzz{\string#}
or some other macro name of your choice.
- 757,742
-
Which is recommended,
\immediate\write18{ps2pdf -dAutoRotatePages\#/None}or\edef\hms{\string#}\immediate\write18{ps2pdf -dAutoRotatePages\hms/None}? – kiss my armpit Nov 05 '13 at 17:28 -
1@Marienplatz it's not a matter of recommended it's what you want, one produces
\#and the other produces#– David Carlisle Nov 05 '13 at 17:33 -
I am a bit confused. So what does
ps2pdfreceive if I use\immediate\write18{ps2pdf -dAutoRotatePages\#/None}instead of\edef\hms{\string#}\immediate\write18{ps2pdf -dAutoRotatePages\hms/None}? – kiss my armpit Nov 05 '13 at 17:35 -
@Marienplatz replace
\immediate\write18{by\immediate\write20{and you'll see what is output. – David Carlisle Nov 05 '13 at 19:03 -
-
The point is that your shell very likely unescapes
\#sops2pdfrecieves only#either case. – yo' Nov 05 '13 at 19:59
It depends on what you want to do. If all you need is to print a # then \# is good; but \# is unexpandable, so in a \write it will be passed as \#. In a \write18 it will be the shell's duty to interpret it correctly. For instance, on a Unix system you can't do
\write18{echo # foo}
(probably a more useful command would be passed), because the shell wouldn't see foo as # is a comment character. Doing
\write18{echo \# foo}
will echo # foo. On the other hand,
\write18{echo '# foo'}
would echo ## foo, because of the peculiar TeX's habit of doubling hash marks in token lists when # has, as usual, category code 6. But
\write18{echo '\# foo'}
would echo \# foo.
So a good strategy is to have a control sequence that expands to a category code 12 hash mark in all cases, given that TeX expands token lists in a \write:
\edef\hashmark{\string#}
Thus
\write 18{echo '\hashmark\space foo'}
will echo # foo.
Unfortunately, different shells tend to have their own idiosyncrasies and with special characters it's always a pain getting equal behavior on all of them on every operating system. Some need quotes around the commands, some don't want them (I guess that Windows has very different conventions than Unix).
- 1,121,712
\#and\%or do you want to expand to a character rather than just typeset it in which case\edef\zzz{\string#}– David Carlisle Nov 05 '13 at 17:19\c_hash_str– user202729 Oct 18 '22 at 11:48