4

I want to make myself a math portofolio (as a quick reference) and I have a part where I have to 'amplify' a fraction like here:

But I don't know how can I do this thing, can you help me? Thank you.

Edit: The "4)" in the upper left-hand corner means "amplify", the process of expanding both numerator and denominator by explicitly stating the value indicated as a multiplication factor. Similarly, a "(4" in the upper right-hand corner means "simplify", or merge the separate values in the numerator and denominator to a single value.

  • 1
    And what exactly should amplify mean in this context? – daleif Jul 27 '15 at 8:45
  • @daleif The thing in the left corner, because eh, this is how we romanians and a part of the world do it. – Stefan Alecu Jul 27 '15 at 8:50
  • @StefanAlecu -- please explain "amplify" in the text of the question. i wasn't familiar with the term either until i read your response to daleif's question, although i was wondering what the "4)" meant. (all the answers so far have neglected that component, and concentrated only on the coloring.) – barbara beeton Jul 27 '15 at 8:56
  • @StefanAlecu -- i've edited in an explanation of "amplify" and "simplify", so that these terms can be found in a search. (it's very hard to search on comments.) if the explanation isn't correct, please fix it. – barbara beeton Jul 27 '15 at 11:33
5

You should define a set of custom markup commands (see [1], [2]) for those fraction types, where you employ the xcolor package and the \prescript command from mathtools to do the needed formatting:

\documentclass{article}
\usepackage{mathtools,xcolor}

\newcommand{\coloredfrac}[3][red]{%
  \frac{\color{#1}#2}{\color{#1}#3}
}

\newcommand{\ampfrac}[3]{%
  \prescript{#1}{}{\frac{#2}{#3}}
}

\newcommand{\simpfrac}[3]{%
  \frac{#2}{#3}^{#1}
}

\begin{document}
\[ \ampfrac{4)}{1}{2}=\coloredfrac{1\cdot 4}{2\cdot 4}=\simpfrac{(4}{4}{8} \]
\end{document}

output


Regarding your request for a more sophisticated coloring macro that is able to color the numerator and the denominator indipendantly you could define:

\newcommand\coloredfrac{\kernel@ifnextchar[{\coloredfrac@}{\coloredfrac@[red]}}
\def\coloredfrac@[#1]{\kernel@ifnextchar[{\coloredfrac@@[#1]}{\coloredfrac@@[#1][#1]}}
\def\coloredfrac@@[#1][#2]#3#4{%
  \frac{\color{#1}#3}{\color{#2}#4}
}

\coloredfrac can now be called

  • without optional arguments to get a colored fraction in the default color, which is red in this example
  • with one optional argument that sets the color for both, the numerator and the denominator
  • with two optional arguments; the first one for the color of the numerator and the second one for the color of the denominator

    \documentclass{article}
    \usepackage{mathtools,xcolor}
    
    \makeatletter
    \newcommand\coloredfrac{\kernel@ifnextchar[{\coloredfrac@}{\coloredfrac@[red]}}% default value: red
    \def\coloredfrac@[#1]{\kernel@ifnextchar[{\coloredfrac@@[#1]}{\coloredfrac@@[#1][#1]}}
    \def\coloredfrac@@[#1][#2]#3#4{%
      \frac{\color{#1}#3}{\color{#2}#4}
    }
    \makeatother
    
    %\newcommand{\ampfrac}[3]{%
    %  \prescript{#1}{}{\frac{#2}{#3}}
    %}
    
    %\newcommand{\simpfrac}[3]{%
    %  \frac{#2}{#3}^{#1}
    %}
    
    \begin{document}
    \[ \coloredfrac{1}{2}=\coloredfrac[green]{2}{4}=\coloredfrac[green][blue]{4}{8} \]
    \end{document}
    

output_add

  • Finally, one answer that answered my question. Thank you. Does it work the other way, to have (4 in the right corner? (that is what we call simplifying) – Stefan Alecu Jul 27 '15 at 9:00
  • Sure, with something like: \newcommand{\simpfrac}[3]{\frac{#2}{#3}^{#1}} – Ruben Jul 27 '15 at 9:05
3

Here is a solution

\documentclass{article}
\usepackage{xcolor}

\begin{document}

\[\raisebox{\baselineskip}{4)}\frac{1}{2}=\frac{\textcolor{red}{1\cdot4}}{\textcolor{red}{2\cdot4}}=\frac{4}{8}\]
\[\raisebox{\baselineskip}{4)}\frac{1}{2}=\frac{\textcolor{red}{1\cdot4}}{\textcolor{red}{2\cdot4}}=\frac{4}{8}\]

\end{document}

enter image description here

  • It's good, but there is a problem. I want to display the thing in the left corner, the 4). That is what I don't know how to do. – Stefan Alecu Jul 27 '15 at 8:52
  • while this takes care of the fractions, it doesn't cover the "4)" in the upper left corner. (see comments on the question. i didn't know what "amplify" meant either, until i read those.) – barbara beeton Jul 27 '15 at 8:53
  • I guess it was also my fault that I didn't specify. – Stefan Alecu Jul 27 '15 at 8:57
  • @StefanAlecu answer edited – touhami Jul 27 '15 at 8:58
1

Do you perhaps mean something like "highlight" by "amplify"?

Anyway, I think

\newcommand{\colorfrac}[3][red]{\frac{{\color{#1} #2}}{{\color{#1} #3}}} 

would suit your purpose.

\colorfrac{1}{2}

would give a red '1/2' and

\colorfrac[green]{1}{3}

a green one (needs the color package).

colorfrac

Edit

As an answer to your comment: Of course you could, manually using \frac{{\color{color1} 1}}{{\color{color2} 2}} or by a command similar to the one defined above.


Okay, now I understood what you want. One solution (\prescribe in the other one is probably better, but still):

\newcommand{\amplfrac}[3]{\frac{\llap{$^{(#1)}$}#2}{#3}}
  • Nope, but at least now I know how to color fractions. Can you color individual parts of a fractions (the top only)? – Stefan Alecu Jul 27 '15 at 8:52
  • edited my answer – Bort Jul 27 '15 at 9:02
  • I think for the individual coloring it is best to have a syntax with optional arguments, like \colorfrac[<color-num>][<color-den>]{<num>}{<den>} -- and \colorfrac[<color-both>]{<num>}{<den>} should be available too (see my answer). – Ruben Jul 27 '15 at 11:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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