mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-09 18:31:04 +00:00
add support for the package cancel in math (fixes #6819); fileformat change only for the preamble handling
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@40663 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
854f42a705
commit
65f26a7a14
@ -87,6 +87,7 @@ src_header_files = Split('''
|
||||
KeySequence.h
|
||||
LaTeX.h
|
||||
LaTeXFeatures.h
|
||||
LaTeXPackages.h
|
||||
Language.h
|
||||
Layout.h
|
||||
LayoutEnums.h
|
||||
@ -189,6 +190,7 @@ src_pre_files = Split('''
|
||||
KeySequence.cpp
|
||||
LaTeX.cpp
|
||||
LaTeXFeatures.cpp
|
||||
LaTeXPackages.cpp
|
||||
Language.cpp
|
||||
Layout.cpp
|
||||
LayoutFile.cpp
|
||||
@ -445,6 +447,8 @@ src_mathed_header_files = Split('''
|
||||
InsetMathBoldSymbol.h
|
||||
InsetMathBox.h
|
||||
InsetMathBrace.h
|
||||
InsetMathCancel.h
|
||||
InsetMathCancelto.h
|
||||
InsetMathCases.h
|
||||
InsetMathChar.h
|
||||
InsetMathColor.h
|
||||
@ -518,6 +522,8 @@ src_mathed_files = Split('''
|
||||
InsetMathBoldSymbol.cpp
|
||||
InsetMathBox.cpp
|
||||
InsetMathBrace.cpp
|
||||
InsetMathCancel.cpp
|
||||
InsetMathCancelto.cpp
|
||||
InsetMathCases.cpp
|
||||
InsetMathChar.cpp
|
||||
InsetMathColor.cpp
|
||||
@ -614,26 +620,36 @@ src_tex2lyx_files = Split('''
|
||||
|
||||
src_tex2lyx_copied_header_files = Split('''
|
||||
TextClass.h
|
||||
graphics/GraphicsParams.h
|
||||
graphics/GraphicsTypes.h
|
||||
insets/ExternalTemplate.h
|
||||
insets/ExternalTransforms.h
|
||||
insets/InsetLayout.h
|
||||
''')
|
||||
|
||||
|
||||
src_tex2lyx_copied_files = Split('''
|
||||
Author.cpp
|
||||
Color.cpp
|
||||
Counters.cpp
|
||||
Encoding.cpp
|
||||
FloatList.cpp
|
||||
Floating.cpp
|
||||
FontInfo.cpp
|
||||
LaTeXPackages.cpp
|
||||
Layout.cpp
|
||||
LayoutFile.cpp
|
||||
LayoutModuleList.cpp
|
||||
Length.cpp
|
||||
lengthcommon.cpp
|
||||
Lexer.cpp
|
||||
ModuleList.cpp
|
||||
Spacing.cpp
|
||||
TextClass.cpp
|
||||
version.cpp
|
||||
graphics/GraphicsParams.cpp
|
||||
insets/ExternalTemplate.cpp
|
||||
insets/ExternalTransforms.cpp
|
||||
insets/InsetLayout.cpp
|
||||
''')
|
||||
|
||||
@ -1354,13 +1370,14 @@ lib_templates_files = Split('''
|
||||
ACM-siggraph.lyx
|
||||
ACM-sigplan.lyx
|
||||
AEA.lyx
|
||||
agutex.lyx
|
||||
agu_article.lyx
|
||||
apa.lyx
|
||||
AGUTeX.lyx
|
||||
AGU_article.lyx
|
||||
APA.lyx
|
||||
beamer-conference-ornate-20min.lyx
|
||||
ctex.lyx
|
||||
de_beamer-conference-ornate-20min.lyx
|
||||
dinbrief.lyx
|
||||
docbook_article.lyx
|
||||
DocBook_article.lyx
|
||||
ectaart.lyx
|
||||
elsarticle.lyx
|
||||
es_beamer-conference-ornate-20min.lyx
|
||||
@ -1371,9 +1388,10 @@ lib_templates_files = Split('''
|
||||
g-brief2.lyx
|
||||
hollywood.lyx
|
||||
IEEEtran.lyx
|
||||
ijmpc.lyx
|
||||
ijmpd.lyx
|
||||
iop-article.lyx
|
||||
IJMPC.lyx
|
||||
IJMPD.lyx
|
||||
IOP-article.lyx
|
||||
JASA.lyx
|
||||
JSS-article.lyx
|
||||
kluwer.lyx
|
||||
koma-letter2.lyx
|
||||
@ -2638,6 +2656,7 @@ lib_doc_fr_clipart_files = Split('''
|
||||
BoxInsetDefaultQt4.png
|
||||
ChildDocumentQt4.png
|
||||
CommentNoteImageQt4.png
|
||||
ERT.png
|
||||
floatQt4.png
|
||||
footnoteQt4.png
|
||||
GreyedOutNoteImageQt4.png
|
||||
@ -2833,7 +2852,9 @@ lib_examples_files = Split('''
|
||||
listerrors.lyx
|
||||
Literate.lyx
|
||||
localization_test.lyx
|
||||
longsheet.gnumeric
|
||||
modernCV.lyx
|
||||
MultilingualCaptions.lyx
|
||||
noweb2lyx.lyx
|
||||
powerdot-example.lyx
|
||||
recipebook.lyx
|
||||
@ -2843,8 +2864,12 @@ lib_examples_files = Split('''
|
||||
serial_letter1.lyx
|
||||
serial_letter2.lyx
|
||||
serial_letter3.lyx
|
||||
sheet1.gnumeric
|
||||
sheet2.ods
|
||||
sheet3.xls
|
||||
simplecv.lyx
|
||||
splash.lyx
|
||||
spreadsheet.lyx
|
||||
sweave.lyx
|
||||
tufte-book.lyx
|
||||
tufte-handout.lyx
|
||||
@ -3086,10 +3111,14 @@ lib_layouts_files = Split('''
|
||||
article.layout
|
||||
article-beamer.layout
|
||||
beamer.layout
|
||||
bicaption.module
|
||||
book.layout
|
||||
broadway.layout
|
||||
chess.layout
|
||||
cl2emult.layout
|
||||
ctex-article.layout
|
||||
ctex-book.layout
|
||||
ctex-report.layout
|
||||
customHeadersFooters.module
|
||||
dinbrief.layout
|
||||
docbook-book.layout
|
||||
@ -3122,6 +3151,7 @@ lib_layouts_files = Split('''
|
||||
iopart.layout
|
||||
isprs.layout
|
||||
jarticle.layout
|
||||
jasatex.layout
|
||||
jbook.layout
|
||||
jgrga.layout
|
||||
jreport.layout
|
||||
@ -3223,6 +3253,7 @@ lib_layouts_inc_files = Split('''
|
||||
theorems-ams.inc
|
||||
theorems-ams-bytype.inc
|
||||
theorems-bytype.inc
|
||||
theorems-case.inc
|
||||
theorems-order.inc
|
||||
theorems-proof.inc
|
||||
theorems-proof-std.inc
|
||||
|
@ -254,6 +254,7 @@
|
||||
\TestPackage{breakurl}
|
||||
\TestPackage{CJKutf8}
|
||||
\TestPackage{calc}
|
||||
\TestPackage{cancel}
|
||||
\TestPackage{color} % this one should be there if graphics.sty is there.
|
||||
\TestPackage{covington}
|
||||
\TestPackage{csquotes}
|
||||
|
@ -450,6 +450,27 @@ def revert_cite_engine_type(document):
|
||||
document.header[i] = "\\cite_engine natbib_" + engine_type
|
||||
|
||||
|
||||
def revert_cancel(document):
|
||||
"add cancel to the preamble if necessary"
|
||||
commands = ["cancelto", "cancel", "bcancel", "xcancel"]
|
||||
i = 0
|
||||
while True:
|
||||
i = find_token(document.body, '\\begin_inset Formula', i)
|
||||
if i == -1:
|
||||
return
|
||||
j = find_end_of_inset(document.body, i)
|
||||
if j == -1:
|
||||
document.warning("Malformed LyX document: Can't find end of Formula inset at line " + str(i))
|
||||
i += 1
|
||||
continue
|
||||
code = "\n".join(document.body[i:j])
|
||||
for c in commands:
|
||||
if code.find("\\%s" % c) != -1:
|
||||
add_to_preamble(document, ["\\usepackage{cancel}"])
|
||||
return
|
||||
i = j
|
||||
|
||||
|
||||
##
|
||||
# Conversion hub
|
||||
#
|
||||
@ -467,10 +488,12 @@ convert = [
|
||||
[422, [convert_use_packages]],
|
||||
[423, [convert_use_mathtools]],
|
||||
[424, [convert_cite_engine_type]],
|
||||
[425, []]
|
||||
]
|
||||
|
||||
revert = [
|
||||
[423, [revert_cite_engine_type]],
|
||||
[424, [revert_cancel]],
|
||||
[423, [revert_cite_engine_type, revert_cancel]],
|
||||
[422, [revert_use_mathtools]],
|
||||
[421, [revert_use_packages]],
|
||||
[420, [revert_longtable_captions]],
|
||||
@ -478,7 +501,7 @@ revert = [
|
||||
[418, [revert_australian]],
|
||||
[417, [revert_justification]],
|
||||
[416, [revert_japanese_encodings]],
|
||||
[415, [revert_negative_space,revert_math_spaces]],
|
||||
[415, [revert_negative_space, revert_math_spaces]],
|
||||
[414, [revert_undertilde]],
|
||||
[413, [revert_visible_space]]
|
||||
]
|
||||
|
@ -728,6 +728,9 @@ string const LaTeXFeatures::getPackages() const
|
||||
params_.use_package("undertilde") != BufferParams::package_off)
|
||||
packages << "\\usepackage{undertilde}\n";
|
||||
|
||||
if (mustProvide("cancel"))
|
||||
packages << "\\usepackage{cancel}\n";
|
||||
|
||||
// [x]color and pdfcolmk are handled in getColorOptions() above
|
||||
|
||||
// makeidx.sty
|
||||
|
@ -364,6 +364,7 @@ EXTRA_DIST += mathed/InsetFormulaMacro.cpp
|
||||
noinst_LIBRARIES += liblyxmathed.a
|
||||
|
||||
SOURCEFILESMATHED = \
|
||||
mathed/CommandInset.cpp \
|
||||
mathed/InsetMathAMSArray.cpp \
|
||||
mathed/InsetMathArray.cpp \
|
||||
mathed/InsetMathBig.cpp \
|
||||
@ -374,7 +375,6 @@ SOURCEFILESMATHED = \
|
||||
mathed/InsetMathCases.cpp \
|
||||
mathed/InsetMathChar.cpp \
|
||||
mathed/InsetMathColor.cpp \
|
||||
mathed/CommandInset.cpp \
|
||||
mathed/InsetMathComment.cpp \
|
||||
mathed/InsetMathDecoration.cpp \
|
||||
mathed/InsetMathDecoration.h \
|
||||
@ -393,7 +393,8 @@ SOURCEFILESMATHED = \
|
||||
mathed/InsetMathKern.cpp \
|
||||
mathed/InsetMathLefteqn.cpp \
|
||||
mathed/InsetMathLim.cpp \
|
||||
mathed/MathMacro.cpp \
|
||||
mathed/InsetMathCancel.cpp \
|
||||
mathed/InsetMathCancelto.cpp \
|
||||
mathed/InsetMathMatrix.cpp \
|
||||
mathed/InsetMathNest.cpp \
|
||||
mathed/InsetMathNumber.cpp \
|
||||
@ -423,6 +424,7 @@ SOURCEFILESMATHED = \
|
||||
mathed/MathData.cpp \
|
||||
mathed/MathExtern.cpp \
|
||||
mathed/MathFactory.cpp \
|
||||
mathed/MathMacro.cpp \
|
||||
mathed/MathMacroArgument.cpp \
|
||||
mathed/MacroTable.cpp \
|
||||
mathed/MathMacroTemplate.cpp \
|
||||
@ -432,16 +434,18 @@ SOURCEFILESMATHED = \
|
||||
mathed/TextPainter.cpp
|
||||
|
||||
HEADERFILESMATHED = \
|
||||
mathed/CommandInset.h \
|
||||
mathed/InsetMathAMSArray.h \
|
||||
mathed/InsetMathArray.h \
|
||||
mathed/InsetMathBig.h \
|
||||
mathed/InsetMathBoldSymbol.h \
|
||||
mathed/InsetMathBox.h \
|
||||
mathed/InsetMathBrace.h \
|
||||
mathed/InsetMathCancel.h \
|
||||
mathed/InsetMathCancelto.h \
|
||||
mathed/InsetMathCases.h \
|
||||
mathed/InsetMathChar.h \
|
||||
mathed/InsetMathColor.h \
|
||||
mathed/CommandInset.h \
|
||||
mathed/InsetMathComment.h \
|
||||
mathed/InsetMathDelim.h \
|
||||
mathed/InsetMathDiff.h \
|
||||
@ -459,7 +463,6 @@ HEADERFILESMATHED = \
|
||||
mathed/InsetMathKern.h \
|
||||
mathed/InsetMathLefteqn.h \
|
||||
mathed/InsetMathLim.h \
|
||||
mathed/MathMacro.h \
|
||||
mathed/InsetMathMatrix.h \
|
||||
mathed/InsetMathNest.h \
|
||||
mathed/InsetMathNumber.h \
|
||||
@ -491,6 +494,7 @@ HEADERFILESMATHED = \
|
||||
mathed/MathExtern.h \
|
||||
mathed/MathFactory.h \
|
||||
mathed/MathGridInfo.h \
|
||||
mathed/MathMacro.h \
|
||||
mathed/MathMacroArgument.h \
|
||||
mathed/MacroTable.h \
|
||||
mathed/MathMacroTemplate.h \
|
||||
|
@ -123,6 +123,8 @@ static void build_translator()
|
||||
insetnames[MATH_BOLDSYMBOL_CODE] = InsetName("mathboldsymbol");
|
||||
insetnames[MATH_BOX_CODE] = InsetName("mathbox");
|
||||
insetnames[MATH_BRACE_CODE] = InsetName("mathbrace");
|
||||
insetnames[MATH_CANCEL_CODE] = InsetName("mathcancel");
|
||||
insetnames[MATH_CANCELTO_CODE] = InsetName("mathcancelto");
|
||||
insetnames[MATH_CASES_CODE] = InsetName("mathcases");
|
||||
insetnames[MATH_CHAR_CODE] = InsetName("mathchar");
|
||||
insetnames[MATH_COLOR_CODE] = InsetName("mathcolor");
|
||||
|
@ -127,105 +127,109 @@ enum InsetCode {
|
||||
///
|
||||
MATH_BRACE_CODE,
|
||||
///
|
||||
MATH_CANCEL_CODE,
|
||||
///
|
||||
MATH_CANCELTO_CODE, // 55
|
||||
///
|
||||
MATH_CASES_CODE,
|
||||
///
|
||||
MATH_CHAR_CODE, // 55
|
||||
MATH_CHAR_CODE,
|
||||
///
|
||||
MATH_COLOR_CODE,
|
||||
///
|
||||
MATH_COMMENT_CODE,
|
||||
///
|
||||
MATH_DECORATION_CODE,
|
||||
MATH_DECORATION_CODE, // 60
|
||||
///
|
||||
MATH_DELIM_CODE,
|
||||
///
|
||||
MATH_DIFF_CODE, // 60
|
||||
MATH_DIFF_CODE,
|
||||
///
|
||||
MATH_DOTS_CODE,
|
||||
///
|
||||
MATH_ENSUREMATH_CODE,
|
||||
///
|
||||
MATH_ENV_CODE,
|
||||
MATH_ENV_CODE, // 65
|
||||
///
|
||||
MATH_EXFUNC_CODE,
|
||||
///
|
||||
MATH_EXINT_CODE, // 65
|
||||
MATH_EXINT_CODE,
|
||||
///
|
||||
MATH_FONT_CODE,
|
||||
///
|
||||
MATH_FONTOLD_CODE,
|
||||
///
|
||||
MATH_FRAC_CODE,
|
||||
MATH_FRAC_CODE, // 70
|
||||
///
|
||||
MATH_GRID_CODE,
|
||||
///
|
||||
MATH_HULL_CODE, // 70
|
||||
MATH_HULL_CODE,
|
||||
///
|
||||
MATH_KERN_CODE,
|
||||
///
|
||||
MATH_LEFTEQN_CODE,
|
||||
///
|
||||
MATH_LIM_CODE,
|
||||
MATH_LIM_CODE, // 75
|
||||
///
|
||||
MATH_MATRIX_CODE,
|
||||
///
|
||||
MATH_MBOX_CODE, // 75
|
||||
MATH_MBOX_CODE,
|
||||
///
|
||||
MATH_NEST_CODE,
|
||||
///
|
||||
MATH_NUMBER_CODE,
|
||||
///
|
||||
MATH_OVERSET_CODE,
|
||||
MATH_OVERSET_CODE, // 80
|
||||
///
|
||||
MATH_PAR_CODE,
|
||||
///
|
||||
MATH_PHANTOM_CODE, // 80
|
||||
MATH_PHANTOM_CODE,
|
||||
///
|
||||
MATH_REF_CODE,
|
||||
///
|
||||
MATH_ROOT_CODE,
|
||||
///
|
||||
MATH_SCRIPT_CODE,
|
||||
MATH_SCRIPT_CODE, // 85
|
||||
///
|
||||
MATH_SIZE_CODE,
|
||||
///
|
||||
MATH_SPACE_CODE, // 85
|
||||
MATH_SPACE_CODE,
|
||||
///
|
||||
MATH_SPECIALCHAR_CODE,
|
||||
///
|
||||
MATH_SPLIT_CODE,
|
||||
///
|
||||
MATH_SQRT_CODE,
|
||||
MATH_SQRT_CODE, // 90
|
||||
///
|
||||
MATH_STACKREL_CODE,
|
||||
///
|
||||
MATH_STRING_CODE,// 90
|
||||
MATH_STRING_CODE,
|
||||
///
|
||||
MATH_SUBSTACK_CODE,
|
||||
///
|
||||
MATH_SYMBOL_CODE,
|
||||
///
|
||||
MATH_TABULAR_CODE,
|
||||
MATH_TABULAR_CODE, // 95
|
||||
///
|
||||
MATH_UNDERSET_CODE,
|
||||
///
|
||||
MATH_UNKNOWN_CODE, // 95
|
||||
MATH_UNKNOWN_CODE,
|
||||
///
|
||||
MATH_XARROW_CODE,
|
||||
///
|
||||
MATH_XYARROW_CODE,
|
||||
///
|
||||
MATH_XYMATRIX_CODE,
|
||||
MATH_XYMATRIX_CODE, // 100
|
||||
///
|
||||
MATH_MACRO_CODE,
|
||||
///
|
||||
ARGUMENT_PROXY_CODE, // 100
|
||||
ARGUMENT_PROXY_CODE,
|
||||
///
|
||||
PREVIEW_CODE,
|
||||
///
|
||||
MATH_DIAGRAM_CODE,
|
||||
///
|
||||
SCRIPT_CODE,
|
||||
SCRIPT_CODE, // 105
|
||||
///
|
||||
INSET_CODE_SIZE
|
||||
};
|
||||
|
134
src/mathed/InsetMathCancel.cpp
Normal file
134
src/mathed/InsetMathCancel.cpp
Normal file
@ -0,0 +1,134 @@
|
||||
/**
|
||||
* \file InsetMathCancel.cpp
|
||||
* This file is part of LyX, the document processor.
|
||||
* Licence details can be found in the file COPYING.
|
||||
*
|
||||
* \author Uwe Stöhr
|
||||
*
|
||||
* Full author contact details are available in file CREDITS.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "InsetMathCancel.h"
|
||||
|
||||
#include "LaTeXFeatures.h"
|
||||
#include "MathStream.h"
|
||||
|
||||
#include "frontends/Painter.h"
|
||||
|
||||
#include <ostream>
|
||||
|
||||
namespace lyx {
|
||||
|
||||
|
||||
InsetMathCancel::InsetMathCancel(Buffer * buf, Kind k)
|
||||
: InsetMathNest(buf, 1), kind_(k)
|
||||
{}
|
||||
|
||||
|
||||
Inset * InsetMathCancel::clone() const
|
||||
{
|
||||
return new InsetMathCancel(*this);
|
||||
}
|
||||
|
||||
|
||||
void InsetMathCancel::metrics(MetricsInfo & mi, Dimension & dim) const
|
||||
{
|
||||
cell(0).metrics(mi, dim);
|
||||
metricsMarkers(dim);
|
||||
}
|
||||
|
||||
|
||||
void InsetMathCancel::draw(PainterInfo & pi, int x, int y) const
|
||||
{
|
||||
// We first draw the text and then an arrow
|
||||
ColorCode const origcol = pi.base.font.color();
|
||||
cell(0).draw(pi, x + 1, y);
|
||||
Dimension const dim = dimension(*pi.base.bv);
|
||||
|
||||
// y1 \ /
|
||||
// \ /
|
||||
// \/
|
||||
// /\
|
||||
// / \
|
||||
// y2 / \
|
||||
// x1 x2
|
||||
|
||||
int const x2 = x + dim.wid;
|
||||
int const x1 = x;
|
||||
int const y1 = y - dim.asc;
|
||||
int const y2 = y + dim.des;
|
||||
|
||||
if (kind_ == cancel)
|
||||
pi.pain.line(x2, y1, x1, y2, origcol);
|
||||
else if (kind_ == bcancel)
|
||||
pi.pain.line(x2, y2, x1, y1, origcol);
|
||||
else if (kind_ == xcancel) {
|
||||
pi.pain.line(x2, y1, x1, y2, origcol);
|
||||
pi.pain.line(x2, y2, x1, y1, origcol);
|
||||
}
|
||||
|
||||
drawMarkers(pi, x, y);
|
||||
}
|
||||
|
||||
|
||||
void InsetMathCancel::write(WriteStream & os) const
|
||||
{
|
||||
MathEnsurer ensurer(os);
|
||||
switch (kind_) {
|
||||
case cancel:
|
||||
os << "\\cancel{";
|
||||
break;
|
||||
case bcancel:
|
||||
os << "\\bcancel{";
|
||||
break;
|
||||
case xcancel:
|
||||
os << "\\xcancel{";
|
||||
break;
|
||||
}
|
||||
os << cell(0) << '}';
|
||||
}
|
||||
|
||||
|
||||
void InsetMathCancel::normalize(NormalStream & os) const
|
||||
{
|
||||
switch (kind_) {
|
||||
case cancel:
|
||||
os << "[cancel ";
|
||||
break;
|
||||
case bcancel:
|
||||
os << "[bcancel ";
|
||||
break;
|
||||
case xcancel:
|
||||
os << "[xcancel ";
|
||||
break;
|
||||
}
|
||||
os << cell(0) << ']';
|
||||
}
|
||||
|
||||
|
||||
void InsetMathCancel::infoize(odocstream & os) const
|
||||
{
|
||||
switch (kind_) {
|
||||
case cancel:
|
||||
os << "Cancel";
|
||||
break;
|
||||
case bcancel:
|
||||
os << "Bcancel";
|
||||
break;
|
||||
case xcancel:
|
||||
os << "Xcancel";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void InsetMathCancel::validate(LaTeXFeatures & features) const
|
||||
{
|
||||
InsetMathNest::validate(features);
|
||||
if (features.runparams().isLaTeX())
|
||||
features.require("cancel");
|
||||
InsetMathNest::validate(features);
|
||||
}
|
||||
|
||||
} // namespace lyx
|
59
src/mathed/InsetMathCancel.h
Normal file
59
src/mathed/InsetMathCancel.h
Normal file
@ -0,0 +1,59 @@
|
||||
// -*- C++ -*-
|
||||
/**
|
||||
* \file InsetMathCancel.h
|
||||
* This file is part of LyX, the document processor.
|
||||
* Licence details can be found in the file COPYING.
|
||||
*
|
||||
* \author Uwe Stöhr
|
||||
*
|
||||
* Full author contact details are available in file CREDITS.
|
||||
*/
|
||||
|
||||
#ifndef MATH_CANCELINSET_H
|
||||
#define MATH_CANCELINSET_H
|
||||
|
||||
#include "InsetMathNest.h"
|
||||
|
||||
|
||||
namespace lyx {
|
||||
|
||||
class InsetMathCancel : public InsetMathNest {
|
||||
public:
|
||||
///
|
||||
enum Kind {
|
||||
cancel,
|
||||
bcancel,
|
||||
xcancel
|
||||
};
|
||||
///
|
||||
explicit InsetMathCancel(Buffer * buf, Kind);
|
||||
///
|
||||
void metrics(MetricsInfo & mi, Dimension & dim) const;
|
||||
///
|
||||
void draw(PainterInfo & pi, int x, int y) const;
|
||||
///
|
||||
void write(WriteStream & os) const;
|
||||
/// write normalized content
|
||||
void normalize(NormalStream & ns) const;
|
||||
///
|
||||
void infoize(odocstream & os) const;
|
||||
///
|
||||
InsetCode lyxCode() const { return MATH_CANCEL_CODE; }
|
||||
/// Nothing for now
|
||||
void mathmlize(MathStream &) const {}
|
||||
/// Nothing for HTML
|
||||
void htmlize(HtmlStream &) const {}
|
||||
///
|
||||
void validate(LaTeXFeatures &) const;
|
||||
|
||||
private:
|
||||
///
|
||||
virtual Inset * clone() const;
|
||||
///
|
||||
Kind kind_;
|
||||
};
|
||||
|
||||
|
||||
|
||||
} // namespace lyx
|
||||
#endif
|
126
src/mathed/InsetMathCancelto.cpp
Normal file
126
src/mathed/InsetMathCancelto.cpp
Normal file
@ -0,0 +1,126 @@
|
||||
/**
|
||||
* \file InsetMathCancelto.cpp
|
||||
* This file is part of LyX, the document processor.
|
||||
* Licence details can be found in the file COPYING.
|
||||
*
|
||||
* \author Uwe Stöhr
|
||||
*
|
||||
* Full author contact details are available in file CREDITS.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "InsetMathCancelto.h"
|
||||
|
||||
#include "Cursor.h"
|
||||
#include "LaTeXFeatures.h"
|
||||
#include "MathData.h"
|
||||
#include "MathStream.h"
|
||||
|
||||
#include "frontends/Painter.h"
|
||||
|
||||
#include <ostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace lyx {
|
||||
|
||||
|
||||
InsetMathCancelto::InsetMathCancelto(Buffer * buf)
|
||||
: InsetMathNest(buf, 2)
|
||||
{}
|
||||
|
||||
|
||||
Inset * InsetMathCancelto::clone() const
|
||||
{
|
||||
return new InsetMathCancelto(*this);
|
||||
}
|
||||
|
||||
|
||||
void InsetMathCancelto::metrics(MetricsInfo & mi, Dimension & dim) const
|
||||
{
|
||||
InsetMathNest::metrics(mi);
|
||||
Dimension const & dim0 = cell(0).dimension(*mi.base.bv);
|
||||
Dimension const & dim1 = cell(1).dimension(*mi.base.bv);
|
||||
dim.asc = max(dim0.ascent() + 2, dim0.ascent() + dim1.ascent()) + 2 + 8;
|
||||
dim.des = max(dim0.descent() - 2, dim1.descent()) + 2;
|
||||
dim.wid = dim0.width() + dim1.width() + 10;
|
||||
metricsMarkers(dim);
|
||||
}
|
||||
|
||||
|
||||
void InsetMathCancelto::draw(PainterInfo & pi, int x, int y) const
|
||||
{
|
||||
ColorCode const origcol = pi.base.font.color();
|
||||
|
||||
// We first draw the text and then an arrow
|
||||
Dimension const & dim0 = cell(0).dimension(*pi.base.bv);
|
||||
cell(0).draw(pi, x + 1, y);
|
||||
cell(1).draw(pi, x + dim0.wid + 2 + 8, y - dim0.asc - 8);
|
||||
|
||||
//Dimension const dim = dimension(*pi.base.bv);
|
||||
|
||||
// y3____ ___
|
||||
// /|
|
||||
// y2_ / |
|
||||
// /
|
||||
// /
|
||||
// /
|
||||
// /
|
||||
// y1 / | |
|
||||
// x1 x2 x3
|
||||
|
||||
int const x2 = x + dim0.wid;
|
||||
int const x3 = x2 + 8;
|
||||
int const x1 = x;
|
||||
int const y1 = y + dim0.des;
|
||||
int const y2 = y - dim0.asc;
|
||||
int const y3 = y2 - 8;
|
||||
|
||||
// the main line
|
||||
pi.pain.line(x3, y3, x1, y1, origcol);
|
||||
// the arrow bars
|
||||
pi.pain.line(x3, y3, x2 + 2, y3, origcol);
|
||||
pi.pain.line(x3, y3, x3 - 2, y2 - 2, origcol);
|
||||
|
||||
drawMarkers(pi, x, y);
|
||||
}
|
||||
|
||||
|
||||
void InsetMathCancelto::write(WriteStream & os) const
|
||||
{
|
||||
MathEnsurer ensurer(os);
|
||||
os << "\\cancelto{" << cell(1) << "}{" << cell(0) << '}';
|
||||
}
|
||||
|
||||
|
||||
void InsetMathCancelto::normalize(NormalStream & os) const
|
||||
{
|
||||
os << "[cancelto " << cell(1) << ' ' << cell(0) << ']';
|
||||
}
|
||||
|
||||
bool InsetMathCancelto::idxUpDown(Cursor & cur, bool up) const
|
||||
{
|
||||
Cursor::idx_type const target = up ? 1 : 0;
|
||||
if (cur.idx() == target)
|
||||
return false;
|
||||
cur.idx() = target;
|
||||
cur.pos() = up ? cur.lastpos() : 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
void InsetMathCancelto::infoize(odocstream & os) const
|
||||
{
|
||||
os << "Cancelto";
|
||||
}
|
||||
|
||||
void InsetMathCancelto::validate(LaTeXFeatures & features) const
|
||||
{
|
||||
InsetMathNest::validate(features);
|
||||
if (features.runparams().isLaTeX())
|
||||
features.require("cancel");
|
||||
InsetMathNest::validate(features);
|
||||
}
|
||||
|
||||
|
||||
} // namespace lyx
|
53
src/mathed/InsetMathCancelto.h
Normal file
53
src/mathed/InsetMathCancelto.h
Normal file
@ -0,0 +1,53 @@
|
||||
// -*- C++ -*-
|
||||
/**
|
||||
* \file InsetMathCancelto.h
|
||||
* This file is part of LyX, the document processor.
|
||||
* Licence details can be found in the file COPYING.
|
||||
*
|
||||
* \author Uwe Stöhr
|
||||
*
|
||||
* Full author contact details are available in file CREDITS.
|
||||
*/
|
||||
|
||||
#ifndef MATH_CANCELTOINSET_H
|
||||
#define MATH_CANCELTOINSET_H
|
||||
|
||||
#include "InsetMathNest.h"
|
||||
|
||||
|
||||
namespace lyx {
|
||||
|
||||
class InsetMathCancelto : public InsetMathNest {
|
||||
public:
|
||||
///
|
||||
explicit InsetMathCancelto(Buffer * buf);
|
||||
///
|
||||
bool idxUpDown(Cursor & cur, bool up) const;
|
||||
///
|
||||
void metrics(MetricsInfo & mi, Dimension & dim) const;
|
||||
///
|
||||
void draw(PainterInfo & pi, int x, int y) const;
|
||||
///
|
||||
void write(WriteStream & os) const;
|
||||
/// write normalized content
|
||||
void normalize(NormalStream & ns) const;
|
||||
///
|
||||
void infoize(odocstream & os) const;
|
||||
///
|
||||
InsetCode lyxCode() const { return MATH_CANCELTO_CODE; }
|
||||
/// Nothing for now
|
||||
void mathmlize(MathStream &) const {}
|
||||
/// Nothing for HTML
|
||||
void htmlize(HtmlStream &) const {}
|
||||
///
|
||||
void validate(LaTeXFeatures &) const;
|
||||
|
||||
private:
|
||||
///
|
||||
virtual Inset * clone() const;
|
||||
};
|
||||
|
||||
|
||||
|
||||
} // namespace lyx
|
||||
#endif
|
@ -2128,6 +2128,10 @@ MathCompletionList::MathCompletionList(Cursor const & cur)
|
||||
globals.push_back(from_ascii("\\hphantom"));
|
||||
globals.push_back(from_ascii("\\phantom"));
|
||||
globals.push_back(from_ascii("\\vphantom"));
|
||||
globals.push_back(from_ascii("\\cancel"));
|
||||
globals.push_back(from_ascii("\\bcancel"));
|
||||
globals.push_back(from_ascii("\\xcancel"));
|
||||
globals.push_back(from_ascii("\\cancelto"));
|
||||
globals.push_back(from_ascii("\\smash"));
|
||||
globals.push_back(from_ascii("\\mathclap"));
|
||||
globals.push_back(from_ascii("\\mathllap"));
|
||||
|
@ -16,6 +16,8 @@
|
||||
#include "InsetMathArray.h"
|
||||
#include "InsetMathBoldSymbol.h"
|
||||
#include "InsetMathBox.h"
|
||||
#include "InsetMathCancel.h"
|
||||
#include "InsetMathCancelto.h"
|
||||
#include "InsetMathCases.h"
|
||||
#include "InsetMathColor.h"
|
||||
#include "InsetMathDecoration.h"
|
||||
@ -501,6 +503,14 @@ MathAtom createInsetMath(docstring const & s, Buffer * buf)
|
||||
return MathAtom(new InsetMathPhantom(buf, InsetMathPhantom::phantom));
|
||||
if (s == "vphantom")
|
||||
return MathAtom(new InsetMathPhantom(buf, InsetMathPhantom::vphantom));
|
||||
if (s == "cancel")
|
||||
return MathAtom(new InsetMathCancel(buf, InsetMathCancel::cancel));
|
||||
if (s == "bcancel")
|
||||
return MathAtom(new InsetMathCancel(buf, InsetMathCancel::bcancel));
|
||||
if (s == "xcancel")
|
||||
return MathAtom(new InsetMathCancel(buf, InsetMathCancel::xcancel));
|
||||
if (s == "cancelto")
|
||||
return MathAtom(new InsetMathCancelto(buf));
|
||||
if (s == "smash")
|
||||
return MathAtom(new InsetMathPhantom(buf, InsetMathPhantom::smash));
|
||||
if (s == "mathclap")
|
||||
|
@ -42,6 +42,7 @@ following hack as starting point to write some macros:
|
||||
#include "InsetMathArray.h"
|
||||
#include "InsetMathBig.h"
|
||||
#include "InsetMathBrace.h"
|
||||
#include "InsetMathCancelto.h"
|
||||
#include "InsetMathChar.h"
|
||||
#include "InsetMathColor.h"
|
||||
#include "InsetMathComment.h"
|
||||
@ -1384,6 +1385,14 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags,
|
||||
}
|
||||
}
|
||||
|
||||
else if (t.cs() == "cancelto") {
|
||||
MathData ar;
|
||||
parse(ar, FLAG_ITEM, mode);
|
||||
cell->push_back(MathAtom(new InsetMathCancelto(buf)));
|
||||
cell->back().nucleus()->cell(1) = ar;
|
||||
parse(cell->back().nucleus()->cell(0), FLAG_ITEM, mode);
|
||||
}
|
||||
|
||||
else if (t.cs() == "unit") {
|
||||
// Allowed formats \unit[val]{unit}
|
||||
MathData ar;
|
||||
|
@ -30,8 +30,8 @@ extern char const * const lyx_version_info;
|
||||
|
||||
// Do not remove the comment below, so we get merge conflict in
|
||||
// independent branches. Instead add your own.
|
||||
#define LYX_FORMAT_LYX 424 // jrioux : \cite_engine_type (authoryear|numerical)
|
||||
#define LYX_FORMAT_TEX2LYX 424 // jrioux : \cite_engine_type (authoryear|numerical)
|
||||
#define LYX_FORMAT_LYX 425 // uwestoehrx: support for the package cancel
|
||||
#define LYX_FORMAT_TEX2LYX 425 // jrioux : \cite_engine_type (authoryear|numerical)
|
||||
|
||||
#if LYX_FORMAT_FOR_TEX2LYX != LYX_FORMAT_FOR_LYX
|
||||
#warning "tex2lyx produces an out of date file format."
|
||||
|
Loading…
Reference in New Issue
Block a user