3

I use Scientific word to generate Latex, and from its GUI, it only supports \fbox to put a frame around a displayed equation. i.e. I select the equation from the GUI and click on a button which adds a frame. The latex it generates adds fbox inside \[...\] and so I have no control over this.

What I can do is add something in the preamble of the latex file that can fix or improve something it does.

The problem is that \fbox seems to change the size of the math on the right side of the equation compared to the left side. When I do the same thing using \boxed I get much better result, which is what I want. (but again, the GUI generates \fbox and there is no way to tell SW to use boxed instead).

Here is a MWE and it is clear that fbox output is not right.

At first I thought if I make the fboxsep larger that will fix it, but that has no effect at all on the font size. Is there something else I can add to preamble to make the result look like \boxed?

One last thing, I can't just change \fbox by \boxed using some smart text replacement macro, as SW will not longer be able to display the equation on the screen then, since it does not know what \boxed is.

\documentclass[11pt]{article}%
\usepackage{amsmath}
\setlength{\fboxsep}{10pt}
\begin{document}

\[
\fbox{$x_1\left(  t\right)  =x_{20}\frac{t}{1+t^2}+\frac{1}{\sqrt{\left(
1+t^2\right)  }}$}%
\]

\[
\boxed{x_1\left(  t\right)  =x_{20}\frac{t}{1+t^2}+\frac{1}{\sqrt{\left(
1+t^2\right)  }}}%
\]

\end{document}

Result is

Mathematica graphics

1
  • A side remark: The code for the equation is not very; I would write it as \[\fbox{$x_1(t) = x_{20} \frac{t}{1 + t^{2}} + \frac{1}{\sqrt{1 + t^{2}}}$}\]. Commented Sep 11, 2014 at 9:43

2 Answers 2

4

One way would be to explicitly switch to \displaystyle within \fbox. This way, the \[...\] can be omitted, unless it should be centered explicitly (well use \begin{center}...\end{center} or \centering (grouped!))

I added a command \mathfbox which does the \[...\] and the displaystyle automatically.

All three ways are shown in the screen shot. The \mathfbox output is the middle one!

\documentclass[11pt]{article}%
\usepackage{amsmath}
\setlength{\fboxsep}{10pt}

\newcommand{\mathfbox}[1]{%
  \[%
  \fbox{%
    \ensuremath{\displaystyle{#1}}%
  }% End of \fbox
  \]%
}%


\begin{document}

\[
\fbox{%
$\displaystyle x_1\left(  t\right)  =x_{20}\frac{t}{1+t^2}+\frac{1}{\sqrt{\left(
1+t^2\right)}}$}%
\]


\mathfbox{x_1\left(  t\right)  =x_{20}\frac{t}{1+t^2}+\frac{1}{\sqrt{\left(1+t^2\right)}}}%

\[
\boxed{x_1\left(  t\right)  =x_{20}\frac{t}{1+t^2}+\frac{1}{\sqrt{\left(
1+t^2\right)  }}}%
\]

\end{document}

This way both boxes look the same ... I suspect, that \boxed is doing nothing different than \fbox{\ensuremath{\displaystyle...}

enter image description here

Update, with redefined \fbox command

\documentclass[11pt]{article}%
\usepackage{amsmath}
\usepackage{xstring}
\usepackage{letltxmacro}% 
\setlength{\fboxsep}{10pt}
\begin{document}


\LetLtxMacro\LaTeXStandardFBox\fbox


\renewcommand{\fbox}[1]{%
  \LaTeXStandardFBox{%
    \expandarg
    \StrSubstitute[1]{#1}{$}{$\displaystyle}%
  }% End of \fbox
}%

\[
\fbox{$x_1\left(  t\right)  =x_{20}\frac{t}{1+t^2}+\frac{1}{\sqrt{\left(1+t^2\right)}}$}%
\]

\let\fbox\LaTeXStandardFBox%
\[
\boxed{x_1\left(  t\right)  =x_{20}\frac{t}{1+t^2}+\frac{1}{\sqrt{\left(
1+t^2\right)  }}}%
\]

\end{document}
9
  • Thanks. But is there a way to write some macro in preamble to do this? i.e. without having to edit the generated code itself? I can't edit the code generated each time and fix this by hand as I mentioned I use SW GUI to generate this code and it is not practical to edit this each time I make changes. Also SW does not understand this new code any more and so it does not display correctly on the screen any more. Here is screen shot from SW to explain the issue !Mathematica graphics
    – Nasser
    Commented Sep 11, 2014 at 7:22
  • @Nasser: See my update
    – user31729
    Commented Sep 11, 2014 at 7:28
  • Thanks again. But I do not think I explained my problem well. I can't add \mathfbox from the GUI. So I have no way to use it when using SW. The issue is that SW generates the fbox and I can only add code to preamble to fix things, but can't edit the code or add code inside the document, since SW will not understand it if it does not supports it in the GUI. The fix has to be to do it all in the preamble only. This way I can still use the GUI but get the correct output when I compile. I hope this explain the problem better.
    – Nasser
    Commented Sep 11, 2014 at 7:36
  • Why don't you add \mathfbox to the preamble????
    – user31729
    Commented Sep 11, 2014 at 7:38
  • I can add \mathfbox to preamble. But this is not the issue. How would I tell SW to use it? I click on a button to add frame around equation. SW generates \fbox. Now what? I can't tell SW to generate code that uses \mathfbox instead. Is there a way to redefine fbox itself to make it do \ensuremath{\displaystyle ? So I do not have to edit the code. Your answer is useful and I can use it when writing direct Latex. But I am using SW at this moment.
    – Nasser
    Commented Sep 11, 2014 at 7:46
5

As usual my advice is to drop front ends to LaTeX if they don't support basic constructions and, like SW, are based on older TeX distributions.

The solution I'll suggest is a hack that will possibly give bad results in other situations. Also, \boxed should be used very sparingly in general (“never” is a good approximation to “very sparingly”).

\documentclass[11pt]{article}
\usepackage{amsmath}

\let\latexfbox\fbox
\renewcommand{\fbox}[1]{%
  \latexfbox{\everymath{\displaystyle}#1}%
}

\begin{document}

\[
\fbox{$x_1\left(  t\right)  =x_{20}\frac{t}{1+t^2}+\frac{1}{\sqrt{\left(
1+t^2\right)  }}$}%
\]

\[
\boxed{x_1\left(  t\right)  =x_{20}\frac{t}{1+t^2}+\frac{1}{\sqrt{\left(
1+t^2\right)  }}}%
\]

\end{document}

enter image description here

1
  • Your solution worked very well also. SW is able to read the latex file ok and display frame on screen since the internal code was not changed and kept as is. Only preamble changed which is ok.
    – Nasser
    Commented Sep 11, 2014 at 8:58

You must log in to answer this question.

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