I was unsatisfied with how the # symbol looked in my document and had a look at this question. I tried to create a simple macro to replace
#
with
\texttt{\#}
I thought that a simple
\renewcommand{\#}{\texttt{\#}}
would do the trick. Instead, I'm getting a fatal (!) error.
[25] [26] [27] [28] [29] (c:/texlive/2017/texmf-dist/tex/latex/base/t1cmtt.fd)
! TeX capacity exceeded, sorry [grouping levels=255].
\hmode@bgroup ->\leavevmode \bgroup
! ==> Fatal error occurred, no output PDF file produced!
Transcript written on Thesis.log.
What is going wrong and why? How can I succesfully create the macro I need?
\#with\texttt{\#}. Since the replacement text (\texttt{\#}) contains\#again you end up with an infinite loop of replacements being attempted. After a while TeX gives up because its capacity is exceeded. – moewe Apr 03 '19 at 10:20\let\oldhash\# \renewcommand{\#}{\texttt{\oldhash}}usually helps. The\let\oldhash\#copies the definition of\#into\oldhashand you can then use\oldhashin the replacement of\#to get the same effect but without the loop. Another way would be\renewcommand{\#}{\texttt{\char"23}}if you know where the#lives in your font. That said, I'm not quite sure if it is absolutely safe to redefine\#, so I would probably choose a new name making it unnecessary to avoid the loop. – moewe Apr 03 '19 at 10:22\let\hashtag\#\renewcommand\#{\texttt{\hashtag}}does work. Though, I'd just define\hashtagto be\texttt{\#}and then use\hashtagthroughout. – daleif Apr 03 '19 at 10:23