2

I want to write clean underscores without backslashes and hyphenate words by underscores.

I tried to use underscore package, but it doesn't work with clean underscores and also breaks includegraphics, when there are underscores in picture name.

MWE:

\documentclass{article}
\usepackage{array}

\begin{document}

    \begin{center}
        \begin{tabular}{ | m{3cm}| } 
            \hline
            SOME\_LONG\_COMMAND  \\\hline
            SOME\_LONG \_COMMAND  \\\hline                  % looks as I want, but stiil have backslashes before underscore
            \detokenize{SOME_LONG_COMMAND}  \\\hline

        \end{tabular}
    \end{center}

\end{document}

1 Answer 1

2

I'm not sure I fully understand your requirements, but I think you need to set up a pair of switches to change the catcode of the underscore (just as \makeatletter and makeatother do for @).

\documentclass{article}
\usepackage[T1]{fontenc}
\newcommand\textunderscoreon{\catcode`_=11}
\newcommand\textunderscoreoff{\catcode`_=8}
\begin{document}
\textunderscoreon
I_CAN_DO_WHAT_I_LIKE_WITH_UNDERSCORES
\textunderscoreoff

NOW\_THEIR\_BEHAVIOUR\_IS\_BACK\_TO\_NORMAL $a_1$
\end{document}

enter image description here

Note that you need to load fontenc or else you will get strange effects, related to the fact that the original TeX fonts have no underscore glyph (they used a short rule in its place).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .