FormulaTexElement.java :  » Math » algebra » ru » susu » algebra » jtex » formula » Java Open Source

Java Open Source » Math » algebra 
algebra » ru » susu » algebra » jtex » formula » FormulaTexElement.java
package ru.susu.algebra.jtex.formula;

import ru.susu.algebra.jtex.StringTexElement;
import ru.susu.algebra.jtex.TexElementBase;
import ru.susu.algebra.jtex.utils.TexUtils;

/**
 * @author akargapolov
 * @since: 23.08.2010
 */
public class FormulaTexElement extends TexElementBase
{
  private boolean _centered = false;

  @Override
  public String generateContent()
  {
    StringBuffer buffer = new StringBuffer();
    buffer.append(_centered ? "$$" : "$").append(generateSubItemsContent()).append(_centered ? "$$" : "$");
    return buffer.toString();
  }

  public FormulaTexElement setCentered()
  {
    _centered = true;
    return this;
  }

  public static FormulaTexElement formula()
  {
    return new FormulaTexElement();
  }

  public static FormulaTexElement formula(String text)
  {
    return (FormulaTexElement)new FormulaTexElement().addSubElement(StringTexElement.text(text));
  }

  public static FormulaTexElement centeredFormula()
  {
    return formula().setCentered();
  }

  public static String frac(String numerator, String denominator)
  {
    return "\\frac{" + numerator + "}{" + denominator + "}";
  }

  private static final String SUM = "\\sum";

  public static String sum(Object from, Object to)
  {
    return SUM + TexUtils.index(from) + TexUtils.pow(to);
  }

  public static String brackets(Object formula)
  {
    return MathSymbols.LEFT + MathSymbols.LEFT_BRACKET + formula + MathSymbols.RIGHT + MathSymbols.RIGHT_BRACKET;
  }

  public static String text(Object text)
  {
    return TEXT + "{" + text + "}";
  }

  public static String sqrt(Object value)
  {
    return "\\sqrt{" + value + "}";
  }

  public static String in(Object value)
  {
    return MathSymbols.IN + "{" + value + "}";
  }

  public static String pmod(Object value)
  {
    return MathSymbols.PMOD + "{" + value + "}";
  }

  public static final String VAREPSILON = "\\varepsilon";
  public static final String IN = "\\in";
  public static final String DEG = "\\deg";
  public static final String CDOT = "\\cdot";
  public static final String LANGLE = "\\langle"; //<
  public static final String RANGLE = "\\rangle"; //>
  public static final String TIMES = "\\times"; //
  private static final String TEXT = "\\text"; //



}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.