2

I can produce two versions from a single latex source. In one version I want to ignore the instances of \hrule. Simply redefining it produces a problem with \hline. Hence the MWE below throws an error, but if we comment out the second line then all is well.

I see from here that one shouldn't redefine \hrule. So, what would be the best practise here?

\documentclass{article}

\renewcommand{\hrule}{}

\begin{document}

\hrule

$\begin{array}{cccccc}
    x & 1 & 2 & 3 & 4 & 5\\\hline
    f(x) & & & & & \\
\end{array}$

\end{document}
3
  • 2
    redefining \hrule in that way will completely break latex, hline is the tip of the iceberg. (ah I just followed your link, and I see it is to me, saying the same thing:-) Mar 29, 2021 at 16:13
  • 1
    You give no indication of what you want to do,. the best practice is simply not to use \hrule rather than define it to nothing then use it, but presumably your real use case doesn't have explicit \hrule in the document? Mar 29, 2021 at 16:15
  • 1
    \hrule is a fairly unusual macro, in no small part because it operates in TeX's "vertical" mode. Unless you really know what you're doing, it's best not to modify the properties of \hrule. In fact, if you don't really know what you're doing, you may be well advised not to use \hrule.
    – Mico
    Mar 29, 2021 at 16:19

1 Answer 1

6

Redefining TeX primitives is almost certain to break LaTeX.

Rather than redefine \hrule use a new command that is defined to be \hrule or not depending on the style you need.

\documentclass{article}

% \newcommand{\myhrule}{}%  plan a
\newcommand{\myhrule}{\hrule}% plan b

\begin{document}

\myhrule

$\begin{array}{cccccc}
    x & 1 & 2 & 3 & 4 & 5\\\hline
    f(x) & & & & & \\
\end{array}$

\end{document}

You must log in to answer this question.

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