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.

I am creating a question sheet using a method (I don't know the exact name, maybe bubble sheet format) as follows:

alt text

My question is how to improve the appearance such that the framed letters get proportional size based on the context. If the frame letter must work as an exponent, it must be smaller. If it works as a lower index in integral or sum, it also must be smaller.

Here is my code snippet after "normalization" :-)

\documentclass[dvipsnames,dvips,cmyk]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{xcolor}
\usepackage{amsmath}
\usepackage{bera}


\fboxsep=2pt
\fboxrule=0.8pt

\newcommand{\boxy}[1]{\ensuremath{\,\fbox{\;\,{\color{red}\bf#1}\,\;}\,}}

\newcommand{\ltr}[1]{{\color{red}\bf#1}}

\begin{document}
\noindent%
Each letter \ltr{A}, \ltr{B}, \ltr{C}, etc in the equations represents a numeral (from 0 to 9) or the minus sign ($-$).


\[
\int_{\boxy{A}}^{\boxy{B}}f(x)\,\textrm{d}x=\frac{1-\boxy{P}}{\boxy{Q}+\boxy{R}}
\]

\[
-2 x^{\boxy{XYZ}}-\boxy{W}\sqrt{\boxy{V}+1}
\]

\[
\sum_{i=\boxy{A}}^{\boxy{BC}}=\tan\left(\boxy{D}-\boxy{E}\right)
\]
\end{document}
share|improve this question

2 Answers 2

up vote 2 down vote accepted

use the \text command, it takes the correct font setting:

\documentclass{article}
\usepackage{xcolor}
\usepackage{amsmath}
\fboxsep=2pt
\fboxrule=0.8pt

\newcommand\boxy[1]{\text{\,\fbox{\;\,{\color{red}$\mathbf{#1}$}\,\;}\,}}

\newcommand{\ltr}[1]{{\color{red}\bf#1}}

\begin{document}
\noindent%
Each letter \ltr{A}, \ltr{B}, \ltr{C}, etc in the equations 
represents a numeral (from 0 to 9) or the minus sign ($-$).
%
\[
\int\limits_{\boxy{A}}^{\boxy{B}}f(x)\,\textrm{d}x=\frac{1-\boxy{P}}{\boxy{Q}+\boxy{R}}
\]
%
\[
-2 x^{\boxy{XYZ}}-\boxy{W}\sqrt{\boxy{V}+1}
\]
%
\[
\sum_{i=\boxy{A}}^{\boxy{BC}}=\tan\left(\boxy{D}-\boxy{E}\right)
\]
\end{document}
share|improve this answer
    
Wow, I'm surprised! Why does this work? –  Hendrik Vogt Dec 28 '10 at 8:58
    
@Hendrik: \text expands to \text@ which expands to a \mathchoice which uses \everymath to set the appropriate style. –  TH. Dec 28 '10 at 9:03
    
@Hendrik: it uses the definitions from mathcoice: \let\f@size#2\selectfont –  Herbert Dec 28 '10 at 9:18
    
@TH.: Ah, \everymath is something I'm not well-acquainted with. No wonder I didn't get it. –  Hendrik Vogt Dec 28 '10 at 9:41
    
thanks for giving me the simplest or most compact (hopely) solution. –  xport Dec 28 '10 at 10:11

You'll want to use \mathpalette: Replace your definition of \boxy with

\makeatletter
\newcommand{\boxy}[1]{\ensuremath{\mathpalette\boxy@helper{#1}}}
\newcommand{\boxy@helper}[2]{\,\fbox{\;\,{\color{red}$\m@th#1\mathbf{#2}$}\,\;}\,}
\makeatother

Note that I made another change to your macro: I use $s and \mathbf in the \fbox, and I added \m@th to ensure that you don't get additional horizontal space.

share|improve this answer
    
Might be worth adding \m@th as well. –  TH. Dec 28 '10 at 8:34
    
@TH.: Thanks! Hope that what I wrote is correct. –  Hendrik Vogt Dec 28 '10 at 8:52
    
thanks for the solution. Even though your solution and Herbert's work, Herbert's is simpler than yours. So I choose Herbert's. :-) –  xport Dec 28 '10 at 10:10
    
@xport: Good choice! –  Hendrik Vogt Dec 28 '10 at 10:12

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.