Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
    
First of all make a compilable example, I get several errors. –  egreg Jul 25 at 15:09
1  
Do you know Why is [ … ] preferable to $$ … $$? –  cgnieder Jul 25 at 15:14

4 Answers 4

up vote 3 down vote accepted

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.

share|improve this answer

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

share|improve this answer

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}
share|improve this answer

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

share|improve this answer
    
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 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 at 19:24
    
I see. I didn't know. I will fix this. Thanks for telling me :). –  MickG Jul 25 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 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 at 18:52

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.