10

Here is an MWE:

\documentclass[a4paper]{report}
\usepackage{graphicx,multirow,multicol}
\makeatletter
\newcommand{\blocks}[9][-10]{
    \def\bar{\@ifstar{\raisebox{-5pt}{\scb{1}[1]{\Huge{|}}}\hsp{0.2cm}}{\raisebox{-14pt}{\scb{1}[1.3]{\Huge{|}}}\hsp{0.2cm}}}

    \!\!\mat{cccc}
        #2&#3\hsp{-0.2cm}&\multicolumn{2}{r}{\multirow{2}{*}{\bar\raisebox{#1pt}{\Huge{$#6$}}}}\\
        #4&#5\hsp{-0.2cm}\\[0.2em]\hline\multicolumn{2}{r}{\multirow{2}{*}{\raisebox{#9pt}{\Huge{$#7$}\hsp{-0.2cm}}}}&\multicolumn{2}{r}{\multirow{2}{*}{\bar*\raisebox{#9pt}{\Huge{$#8$}}}}\\
        \\
        \emat\!\!}
\makeatother
\newcommand{\mat}{\begin{array}}
\newcommand{\emat}{\end{array}}
\newcommand{\scb}{\scalebox}
\newcommand{\hsp}{\hspace}

\begin{document}
$$\blocks{\cosh u}{\sinh u}{\sinh u}{\cosh u}{0}{0}{1}.$$
\end{document}

Typesetting it generates what I expect, except that the | appear as horizontal bars. Why? And why does changing them to $|$ turn them vertical?

MickG
  • 5,426

4 Answers4

11

the ascii | has the internal code "7C.

in computer modern text fonts, position "7C is occupied by the em-dash.

when you pack something into a box (\raisebox here), it reverts to horizontal mode, hence | accesses the em-dash.

as you have discovered, $|$ accesses the vertical bar, because in the math font, the ascii position is used for this symbol.

by pure blind luck, you have hit on a combination that looks like all that it changes is the orientation of the shape. if you want the bar to be vertical, remember that it has to be in math mode if it's in a box.

5

It's really a bad idea to redefine \bar. Plus you're doing by hand things that are already available, using characters that are not what you're expecting: typing | in text mode is not really a good idea, unless you're loading the T1 encoding.

\documentclass[a4paper]{report}
\newcommand{\blocks}[7]{%
  \begin{array}{c|c}
  \begin{array}{@{}cc@{}}
  #1 & #2 \\
  #3 & #4
  \end{array} &
  \xbox[-0.8ex]{#5} \\[2ex]
  \hline
  & \\[-1.5ex]
  \xbox{#6} &
  \xbox{#7}
  \end{array}%
}
\newcommand\xbox[2][0pt]{%
  \begin{tabular}{@{}c@{}}\raisebox{#1}{\Huge\ $#2$\ }\end{tabular}% 
}

\begin{document}
\[
\blocks{\cosh u}{\sinh u}{\sinh u}{\cosh u}{0}{0}{1}
\]
\end{document}

enter image description here

egreg
  • 1,121,712
  • By "redefine" do you mean \bar already has a definition or do you just mean I shouldn't redefine it every time I call \blocks? – MickG Jul 25 '14 at 18:44
  • @MickG It has a definition, the “bar” math accent, so it's not wise to redefine it. For the general problem, one redefines something if its definition should depend on current conditions. – egreg Jul 25 '14 at 19:24
  • I see. I didn't know. I will fix this. Thanks for telling me :). – MickG Jul 25 '14 at 20:16
  • PS it should be \newcommand{\xbox} with braces around \xbox, shouldn't it? And the tabular around the \raisebox in \xbox? What is it for? – MickG Jul 26 '14 at 18:17
  • \newcommand{\xbox} and \newcommand\xbox are equivalent. The tabular is for vertical centering and for using \Huge inside it. – egreg Jul 26 '14 at 18:52
  • Uh-huh. What if I want \hline and | in the 2x2 submatrix? How do I get the \hline to extend to the border of the column? And why do you say the tabular is «for using \Huge inside it»? – MickG Jul 26 '14 at 20:06
  • @MickG I can't follow you. You seem to favor complications. – egreg Jul 26 '14 at 20:07
  • Never mind, I've solved that myself. Just have to fiddle with the padding spaces. But in what sense do you need a tabular to use \Huge in it? – MickG Jul 26 '14 at 20:38
  • @MickG Just because it's easier: in an array I would have to use \mbox{\Huge$0$}, while in atabular` cells are in text mode. – egreg Jul 26 '14 at 20:48
  • But then @egreg since it is in a \raisebox the \mbox shouldn't be needed, right? I mean, my example (except for the \par being generated by the double line feed) works, and there is no tabular. – MickG Jul 26 '14 at 21:06
4

The example shows many issues, some of them:

Example:

\documentclass[a4paper]{report}

\makeatletter
\newcommand*{\blocks}[7]{%
  \begingroup
    \newcommand*{\hugemath}[1]{\mbox{\Huge$##1$}}%
    \begin{tabular}{r|l}
      $%
        % @{} removes space at the left and right, because
        % the surrounding tabular adds already space.
        \begin{array}[b]{@{}cc@{}}
          #1&#2\\
          #3&#4%
        \end{array}
      $%
      & \mbox{\Huge$#5$}\\
      \hline
      % the following trick adds vertical space above
      % the contents of the row with the amount of the depth
      % of a table line. Then the `\hline` is in the middle.
      % \@finalstrut\@arstrutbox is the depth of a tabular
      % line (e.g. this is added at the end of a line in
      % a cell of column type "p".
      \settodepth{\dimen@}{\@finalstrut\@arstrutbox}%
      \raisebox{\dimen@}{%
        \vphantom{\hugemath#6#7}%
      }%
      \hugemath{#6}
      & \hugemath{#7}%
    \end{tabular}%
  \endgroup
}
\makeatother

\begin{document}
\[
  \blocks{\cosh u}{\sinh u}{\sinh u}{\cosh u}{0}{0}{1}
\]
\end{document}

Result

Heiko Oberdiek
  • 271,626
3

The default OT1 encoding has ligatures (emdash here) and other things in the ascii punctuation slots, try

\documentclass{article}

\begin{document}

OT1 is strange < | >

\end{document}
David Carlisle
  • 757,742