3 * Purpose: Implementation of formula inset
4 * Author: Alejandro Aguilar Sierra <asierra@servidor.unam.mx>
5 * Created: January 1996
6 * Description: Allows the edition of math paragraphs inside Lyx.
8 * Copyright: 1996-1998 Alejandro Aguilar Sierra
10 * Version: 0.4, Lyx project.
12 * You are free to use and modify this code under the terms of
13 * the GNU General Public Licence version 2 or later.
22 #pragma implementation
26 #include "formulamacro.h"
27 #include "commandtags.h"
28 #include "math_cursor.h"
29 #include "math_parser.h"
30 #include "BufferView.h"
34 #include "LaTeXFeatures.h"
36 #include "support/LOstream.h"
40 #include "math_arrayinset.h"
41 #include "math_spaceinset.h"
42 #include "support/lyxlib.h"
43 #include "mathed/support.h"
44 #include "undo_funcs.h"
50 extern char const * latex_special_chars;
52 int greek_kb_flag = 0;
53 extern char const * latex_mathenv[];
54 LyXFont * Math_Fonts = 0;
55 MathCursor * mathcursor = 0;
66 void mathed_init_fonts();
68 string nicelabel(string const & label)
70 return "(" + (label.empty() ? "#" : label) + ")";
73 void handleFont(BufferView * bv, MathTextCodes t)
75 if (mathcursor->Selection())
76 bv->lockedInsetStoreUndo(Undo::EDIT);
77 mathcursor->handleFont(t);
80 void handleAccent(BufferView * bv, int code)
82 bv->lockedInsetStoreUndo(Undo::EDIT);
83 mathcursor->handleAccent(code);
86 void handleDelim(BufferView * bv, int l, int r)
88 bv->lockedInsetStoreUndo(Undo::EDIT);
89 mathcursor->handleDelim(l, r);
92 bool openNewInset(BufferView * bv, UpdatableInset * new_inset)
94 LyXText * lt = bv->getLyXText();
98 if (!bv->insertInset(new_inset)) {
102 new_inset->edit(bv, 0, 0, 0);
111 LyXFont WhichFont(short type, int size)
148 case LM_TC_SPECIAL: //f = Math_Fonts[0]; break;
161 if (type == LM_TC_BSYM) {
174 case LM_ST_SCRIPTSCRIPT:
180 lyxerr << "Math Error: wrong font size: " << size << endl;
184 if (type != LM_TC_TEXTRM)
185 f.setColor(LColor::math);
193 void mathed_init_fonts()
195 Math_Fonts = new LyXFont[8]; //DEC cxx cannot initialize all fonts
198 for (int i = 0 ; i < 8 ; ++i) {
199 Math_Fonts[i] = LyXFont(LyXFont::ALL_SANE);
202 Math_Fonts[0].setShape(LyXFont::ITALIC_SHAPE);
204 Math_Fonts[1].setFamily(LyXFont::SYMBOL_FAMILY);
206 Math_Fonts[2].setFamily(LyXFont::SYMBOL_FAMILY);
207 Math_Fonts[2].setShape(LyXFont::ITALIC_SHAPE);
209 Math_Fonts[3].setSeries(LyXFont::BOLD_SERIES);
211 Math_Fonts[4].setFamily(LyXFont::SANS_FAMILY);
212 Math_Fonts[4].setShape(LyXFont::ITALIC_SHAPE);
214 Math_Fonts[5].setFamily(LyXFont::TYPEWRITER_FAMILY);
216 Math_Fonts[6].setFamily(LyXFont::ROMAN_FAMILY);
218 Math_Fonts[7].setFamily(LyXFont::SANS_FAMILY);
222 // returns the nearest enclosing matrix
223 MathArrayInset * matrixpar(int & idx)
227 static_cast<MathArrayInset *>
228 (mathcursor ? mathcursor->enclosing(LM_OT_MATRIX, idx) : 0);
235 InsetFormulaBase::InsetFormulaBase(MathInset * par)
240 InsetFormulaBase::InsetFormulaBase(InsetFormulaBase const & f)
241 : UpdatableInset(f), par_(static_cast<MathInset *>(f.par_->clone()))
245 InsetFormulaBase::~InsetFormulaBase()
248 #warning leak this for a while...
254 void InsetFormulaBase::read(Buffer const *, LyXLex & lex)
259 void InsetFormulaBase::write(Buffer const *, ostream & os) const
264 int InsetFormulaBase::latex(Buffer const *, ostream & os,
265 bool fragile, bool spacing) const
267 return latex(os, fragile, spacing);
270 int InsetFormulaBase::ascii(Buffer const *, ostream & os, int spacing) const
272 return ascii(os, spacing);
275 int InsetFormulaBase::linuxdoc(Buffer const *, ostream & os) const
280 int InsetFormulaBase::docBook(Buffer const *, ostream & os) const
287 // Check if uses AMS macros
288 void InsetFormulaBase::validate(LaTeXFeatures &) const
292 string const InsetFormulaBase::editMessage() const
294 return _("Math editor mode");
298 void InsetFormulaBase::edit(BufferView * bv, int x, int /*y*/, unsigned int)
300 mathcursor = new MathCursor(this);
302 if (!bv->lockInset(this))
303 lyxerr[Debug::MATHED] << "Cannot lock inset!!!" << endl;
305 par_->Metrics(LM_ST_TEXT);
306 bv->updateInset(this, false);
318 void InsetFormulaBase::insetUnlock(BufferView * bv)
321 if (mathcursor->InMacroMode()) {
322 mathcursor->MacroModeClose();
328 bv->updateInset(this, false);
332 void InsetFormulaBase::getCursorPos(BufferView *, int & x, int & y) const
334 mathcursor->GetPos(x, y);
340 void InsetFormulaBase::toggleInsetCursor(BufferView * bv)
345 if (isCursorVisible())
346 bv->hideLockedInsetCursor();
350 mathcursor->GetPos(x, y);
354 LyXFont font = WhichFont(LM_TC_TEXTRM, LM_ST_TEXT);
355 int const asc = lyxfont::maxAscent(font);
356 int const desc = lyxfont::maxDescent(font);
358 bv->showLockedInsetCursor(x, y, asc, desc);
361 toggleCursorVisible();
365 void InsetFormulaBase::showInsetCursor(BufferView * bv, bool)
367 if (!isCursorVisible()) {
371 mathcursor->GetPos(x, y);
374 LyXFont font = WhichFont(LM_TC_TEXTRM, LM_ST_TEXT);
375 int const asc = lyxfont::maxAscent(font);
376 int const desc = lyxfont::maxDescent(font);
377 bv->fitLockedInsetCursor(x, y, asc, desc);
379 toggleInsetCursor(bv);
384 void InsetFormulaBase::hideInsetCursor(BufferView * bv)
386 if (isCursorVisible())
387 toggleInsetCursor(bv);
391 void InsetFormulaBase::toggleInsetSelection(BufferView * bv)
396 bv->updateInset(this, false);
400 vector<string> const InsetFormulaBase::getLabelList() const
402 return std::vector<string>();
406 void InsetFormulaBase::updateLocal(BufferView * bv)
408 par_->Metrics(LM_ST_TEXT);
409 bv->updateInset(this, true);
413 void InsetFormulaBase::insetButtonRelease(BufferView * bv,
414 int x, int y, int /*button*/)
420 mathcursor->SetPos(x, y);
427 bv->updateInset(this, false);
432 void InsetFormulaBase::insetButtonPress(BufferView * bv,
433 int x, int y, int /*button*/)
438 if (mathcursor && mathcursor->Selection()) {
439 mathcursor->SelClear();
440 bv->updateInset(this, false);
445 void InsetFormulaBase::insetMotionNotify(BufferView * bv,
446 int x, int y, int /*button*/)
448 if (sel_x && sel_y && abs(x-sel_x) > 4 && !sel_flag) {
451 mathcursor->SetPos(sel_x + par_->xo(), sel_y + par_->yo());
452 mathcursor->SelStart();
454 mathcursor->GetPos(sel_x, sel_y);
455 } else if (sel_flag) {
459 mathcursor->SetPos(x, y);
461 mathcursor->GetPos(x, y);
462 if (sel_x != x || sel_y != y)
463 bv->updateInset(this, false);
470 void InsetFormulaBase::insetKeyPress(XKeyEvent *)
472 lyxerr[Debug::MATHED]
473 << "Used InsetFormulaBase::InsetKeyPress." << endl;
478 UpdatableInset::RESULT
479 InsetFormulaBase::localDispatch(BufferView * bv, kb_action action,
482 //lyxerr << "InsetFormulaBase::LocalDispatch: act: " << action
483 // << " arg: '" << arg << "' cursor: " << mathcursor << "\n";
488 MathTextCodes varcode = LM_TC_MIN;
489 bool was_macro = mathcursor->InMacroMode();
491 bool was_selection = mathcursor->Selection();
492 RESULT result = DISPATCHED;
496 if (mathcursor->getLastCode() == LM_TC_TEX)
499 mathcursor->normalize();
503 // --- Cursor Movements ---------------------------------------------
506 sel = true; // fall through...
509 result = DISPATCH_RESULT(mathcursor->Right(sel));
515 sel = true; // fall through
518 result = DISPATCH_RESULT(mathcursor->Left(sel));
527 result = DISPATCH_RESULT(mathcursor->Up(sel));
536 result = DISPATCH_RESULT(mathcursor->Down(sel));
550 case LFUN_DELETE_LINE_FORWARD:
551 bv->lockedInsetStoreUndo(Undo::DELETE);
552 mathcursor->DelLine();
557 mathcursor->idxNext();
562 mathcursor->idxPrev();
567 bv->lockedInsetStoreUndo(Undo::EDIT);
568 mathcursor->splitCell();
573 if (!mathcursor->InMacroMode() && mathcursor->pos() == 0) {
574 bv->lockedInsetStoreUndo(Undo::DELETE);
575 mathcursor->pullArg();
576 bv->updateInset(this, true);
579 if (!mathcursor->Left())
584 bv->lockedInsetStoreUndo(Undo::DELETE);
585 mathcursor->Delete();
586 bv->updateInset(this, true);
590 // sprintf(dispatch_buffer, "%d %d",);
591 // dispatch_result = dispatch_buffer;
595 lyxerr << "LFUN_SETXY broken!\n";
600 istringstream is(arg.c_str());
603 mathcursor->SetPos(x1 + x, y1 + y);
608 // cursor selection ----------------------------
612 mathcursor->MacroModeClose();
613 bv->lockedInsetStoreUndo(Undo::INSERT);
614 mathcursor->SelPaste();
619 bv->lockedInsetStoreUndo(Undo::DELETE);
620 mathcursor->SelCut();
625 mathcursor->SelCopy();
630 case LFUN_WORDRIGHTSEL:
631 case LFUN_WORDLEFTSEL:
634 // --- accented characters ------------------------------
636 case LFUN_UMLAUT: handleAccent(bv, LM_ddot); break;
637 case LFUN_CIRCUMFLEX: handleAccent(bv, LM_hat); break;
638 case LFUN_GRAVE: handleAccent(bv, LM_grave); break;
639 case LFUN_ACUTE: handleAccent(bv, LM_acute); break;
640 case LFUN_TILDE: handleAccent(bv, LM_tilde); break;
641 case LFUN_MACRON: handleAccent(bv, LM_bar); break;
642 case LFUN_DOT: handleAccent(bv, LM_dot); break;
643 case LFUN_CARON: handleAccent(bv, LM_check); break;
644 case LFUN_BREVE: handleAccent(bv, LM_breve); break;
645 case LFUN_VECTOR: handleAccent(bv, LM_vec); break;
649 if (!greek_kb_flag) {
651 bv->owner()->message(_("Math greek mode on"));
657 case LFUN_GREEK_TOGGLE:
658 greek_kb_flag = greek_kb_flag ? 0 : 2;
660 bv->owner()->message(_("Math greek keyboard on"));
662 bv->owner()->message(_("Math greek keyboard off"));
666 case LFUN_BOLD: handleFont(bv, LM_TC_BF); break;
667 case LFUN_SANS: handleFont(bv, LM_TC_SF); break;
668 case LFUN_EMPH: handleFont(bv, LM_TC_CAL); break;
669 case LFUN_ROMAN: handleFont(bv, LM_TC_RM); break;
670 case LFUN_CODE: handleFont(bv, LM_TC_TT); break;
671 case LFUN_DEFAULT: handleFont(bv, LM_TC_VAR); break;
674 handleFont(bv, LM_TC_TEXTRM);
675 //bv->owner()->message(_("math text mode toggled"));
680 if (!mathcursor->Selection()) {
681 mathcursor->handleFont(LM_TC_TEX);
682 //bv->owner()->message(_("TeX mode toggled"));
687 case LFUN_MATH_LIMITS:
688 bv->lockedInsetStoreUndo(Undo::INSERT);
689 if (mathcursor->toggleLimits())
695 bv->lockedInsetStoreUndo(Undo::INSERT);
696 latexkeys const * l = in_word_set(arg);
697 mathcursor->SetSize(MathStyles(l ? l->id : static_cast<unsigned int>(-1)));
702 case LFUN_INSERT_MATRIX:
704 bv->lockedInsetStoreUndo(Undo::INSERT);
705 mathcursor->Interpret("matrix " + arg);
710 case LFUN_INSERT_MATH:
712 bv->lockedInsetStoreUndo(Undo::INSERT);
713 mathcursor->Interpret(arg);
718 case LFUN_MATH_DELIM:
720 bv->lockedInsetStoreUndo(Undo::INSERT);
723 static const string vdelim("(){}[]./|");
724 lyxerr << "formulabase::LFUN_MATH_DELIM, arg: '" << arg << "'\n";
729 istringstream is(arg.c_str());
733 lyxerr << "formulabase::LFUN_MATH_DELIM, lt: '" << lt << "'\n";
734 lyxerr << "formulabase::LFUN_MATH_DELIM, rt: '" << rt << "'\n";
737 latexkeys const * l = in_word_set(lt);
740 } else if (vdelim.find(lt[0]) != string::npos)
744 latexkeys const * l = in_word_set(rt);
747 } else if (vdelim.find(rt[0]) != string::npos)
750 handleDelim(bv, ilt, irt);
755 case LFUN_PROTECTEDSPACE:
756 bv->lockedInsetStoreUndo(Undo::INSERT);
757 mathcursor->insert(new MathSpaceInset(1));
762 bv->owner()->message(_("Invalid action in math mode!"));
766 case LFUN_MATH_HALIGN:
768 bv->lockedInsetStoreUndo(Undo::INSERT);
769 lyxerr << "handling halign '" << arg << "'\n";
771 MathArrayInset * p = matrixpar(idx);
774 p->halign(arg.size() ? arg[0] : 'c', p->col(idx));
779 case LFUN_MATH_VALIGN:
781 bv->lockedInsetStoreUndo(Undo::INSERT);
782 lyxerr << "handling valign '" << arg << "'\n";
784 MathArrayInset * p = matrixpar(idx);
787 p->valign(arg.size() ? arg[0] : 'c');
792 case LFUN_MATH_ROW_INSERT:
794 bv->lockedInsetStoreUndo(Undo::INSERT);
796 MathArrayInset * p = matrixpar(idx);
797 lyxerr << " calling LFUN_MATH_ROW_INSERT on " << p << endl;
800 p->addRow(p->row(idx));
805 case LFUN_MATH_ROW_DELETE:
807 bv->lockedInsetStoreUndo(Undo::INSERT);
809 MathArrayInset * p = matrixpar(idx);
810 lyxerr << " calling LFUN_MATH_ROW_DELETE on " << p << endl;
813 p->delRow(p->row(idx));
818 case LFUN_MATH_COLUMN_INSERT:
820 bv->lockedInsetStoreUndo(Undo::INSERT);
822 MathArrayInset * p = matrixpar(idx);
825 p->addCol(p->col(idx));
830 case LFUN_MATH_COLUMN_DELETE:
832 bv->lockedInsetStoreUndo(Undo::INSERT);
834 MathArrayInset * p = matrixpar(idx);
837 p->delCol(p->col(idx));
842 case LFUN_EXEC_COMMAND:
843 result = UNDISPATCHED;
847 if ((action == -1 || action == LFUN_SELFINSERT) && !arg.empty()) {
848 unsigned char c = arg[0];
849 //lyxerr << "char: '" << c << "' int: " << int(c) << endl;
850 //owner_->getIntl()->getTrans().TranslateAndInsert(c, lt);
851 //lyxerr << "trans: '" << c << "' int: " << int(c) << endl;
852 bv->lockedInsetStoreUndo(Undo::INSERT);
854 if (c == 0) { // Dead key, do nothing
855 //lyxerr << "deadkey" << endl;
860 if (mathcursor->getLastCode() == LM_TC_TEX) {
861 mathcursor->MacroModeOpen();
862 mathcursor->clearLastCode();
864 } else if (!varcode) {
865 short f = mathcursor->getLastCode() ?
866 mathcursor->getLastCode() :
867 mathcursor->nextCode();
868 varcode = MathIsAlphaFont(f) ?
869 static_cast<MathTextCodes>(f) :
873 // lyxerr << "Varcode << vardoce;
874 MathTextCodes char_code = varcode;
877 {'A', 'B', 'X', 0 , 'E', 0 , 0 , 'H', 'I', 0 ,
878 'K', 0 , 'M', 'N', 'O', 0 , 0 , 'P', 0 , 'T',
879 'Y', 0, 0, 0, 0 , 'Z' };
881 if ('A' <= c && c <= 'Z' && greek[c - 'A']) {
882 char_code = LM_TC_RM;
885 char_code = LM_TC_SYMB;
888 mathcursor->insert(c, char_code);
890 if (greek_kb_flag && char_code == LM_TC_RM )
891 mathcursor->setLastCode(LM_TC_VAR);
895 if (greek_kb_flag < 2)
898 } else if (strchr("!,:;{}", c) && (varcode == LM_TC_TEX||was_macro)) {
899 mathcursor->insert(c, LM_TC_TEX);
901 mathcursor->insert('}', LM_TC_TEX);
904 mathcursor->clearLastCode();
905 // varcode = LM_TC_MIN;
906 } else if (c == '_' && varcode == LM_TC_TEX) {
907 mathcursor->insert(c, LM_TC_SPECIAL);
908 mathcursor->clearLastCode();
909 // varcode = LM_TC_MIN;
910 } else if ('0' <= c && c <= '9' && (varcode == LM_TC_TEX||was_macro)) {
911 mathcursor->MacroModeOpen();
912 mathcursor->clearLastCode();
913 mathcursor->insert(c, LM_TC_MIN);
914 } else if (('0' <= c && c <= '9') || strchr(";:!|[]().,?", c)) {
915 MathTextCodes code = mathcursor->getLastCode();
916 if (code != LM_TC_TEXTRM)
918 mathcursor->insert(c, code);
919 } else if (strchr("+/-*<>=", c)) {
920 MathTextCodes code = mathcursor->getLastCode();
921 if (code != LM_TC_TEXTRM)
923 mathcursor->insert(c, code);
924 } else if (strchr(latex_special_chars, c) && c != '_') {
925 MathTextCodes code = mathcursor->getLastCode();
926 if (code != LM_TC_TEXTRM)
927 code = LM_TC_SPECIAL;
928 mathcursor->insert(c, code);
929 } else if (c == '_' || c == '^') {
933 mathcursor->Interpret(s);
934 } else if (c == ' ') {
936 short f = (mathcursor->getLastCode()) ?
937 mathcursor->getLastCode() :
938 mathcursor->nextCode();
939 varcode = MathIsAlphaFont(f) ?
940 static_cast<MathTextCodes>(f) :
944 if (varcode == LM_TC_TEXTRM) {
945 mathcursor->insert(c, LM_TC_TEXTRM);
946 } else if (was_macro) {
947 mathcursor->MacroModeClose();
949 if (!mathcursor->pop())
951 mathcursor->plainRight();
953 } else if (c == '\'' || c == '@') {
954 mathcursor->insert (c, LM_TC_VAR);
955 } else if (c == '\\') {
957 mathcursor->MacroModeClose();
958 bv->owner()->message(_("TeX mode"));
959 mathcursor->setLastCode(LM_TC_TEX);
962 } else if (action == LFUN_MATH_PANEL) {
963 result = UNDISPATCHED;
965 lyxerr << "Closed by action " << action << endl;
970 mathcursor->normalize();
972 if (mathcursor && was_macro != mathcursor->InMacroMode()
974 && action != LFUN_BACKSPACE)
980 if (mathcursor && (mathcursor->Selection() || was_selection))
981 toggleInsetSelection(bv);
983 if (result == DISPATCHED || result == DISPATCHED_NOUPDATE ||
984 result == UNDISPATCHED)
987 bv->unlockInset(this);
989 return result; // original version
994 /* FIXME: math-greek-toggle seems to work OK, but math-greek doesn't turn
996 bool math_insert_greek(BufferView * bv, char c)
998 if (!bv->available())
1006 if (!bv->theLockingInset() || bv->theLockingInset()->isTextInset()) {
1007 int greek_kb_flag_save = greek_kb_flag;
1008 InsetFormula * new_inset = new InsetFormula();
1009 bv->beforeChange(bv->text);
1010 if (!bv->insertInset(new_inset)) {
1015 new_inset->edit(bv, 0, 0, 0);
1016 new_inset->localDispatch(bv, LFUN_SELFINSERT, tmp);
1017 if (greek_kb_flag_save < 2) {
1018 bv->unlockInset(new_inset); // bv->theLockingInset());
1019 bv->text->cursorRight(bv, true);
1022 if (bv->theLockingInset()->lyxCode() == Inset::MATH_CODE ||
1023 bv->theLockingInset()->lyxCode() == Inset::MATHMACRO_CODE)
1024 static_cast<InsetFormula*>(bv->theLockingInset())->localDispatch(bv, LFUN_SELFINSERT, tmp);
1026 lyxerr << "Math error: attempt to write on a wrong "
1027 "class of inset." << endl;
1033 Inset::Code InsetFormulaBase::lyxCode() const
1035 return Inset::MATH_CODE;
1039 LyXFont const InsetFormulaBase::convertFont(LyXFont const & f) const
1041 // We have already discussed what was here
1044 font.setLatex(LyXFont::OFF);
1049 MathInset * InsetFormulaBase::par() const
1055 void mathDispatchCreation(BufferView * bv, string const & arg, bool display)
1057 if (bv->available()) {
1058 // Feature "Read math inset from selection" disabled.
1059 // // use selection if available..
1061 // if (action == LFUN_MATH_IMPORT_SELECTION)
1064 // sel = bv->getLyXText()->selectionAsString(bv->buffer());
1067 // if (sel.empty()) {
1068 f = new InsetFormula;
1069 if (openNewInset(bv, f)) {
1070 // don't do that also for LFUN_MATH_MODE unless you want end up with
1071 // always changing to mathrm when opening an inlined inset
1072 // -- I really hate "LyXfunc overloading"...
1074 f->localDispatch(bv, LFUN_MATH_DISPLAY, string());
1075 f->localDispatch(bv, LFUN_INSERT_MATH, arg);
1078 // f = new InsetFormula(sel);
1079 // bv->getLyXText()->cutSelection(bv);
1080 // openNewInset(bv, f);
1083 bv->owner()->getLyXFunc()->setMessage(N_("Math editor mode"));
1086 void mathDispatchMathDisplay(BufferView * bv, string const & arg)
1088 mathDispatchCreation(bv, arg, true);
1091 void mathDispatchMathMode(BufferView * bv, string const & arg)
1093 mathDispatchCreation(bv, arg, false);
1096 void mathDispatchMathImportSelection(BufferView * bv, string const & arg)
1098 mathDispatchCreation(bv, arg, true);
1101 void mathDispatchMathMacro(BufferView * bv, string const & arg)
1103 if (bv->available()) {
1106 bv->owner()->getLyXFunc()->setErrorMessage(N_("Missing argument"));
1108 string const s1 = token(s, ' ', 1);
1109 int const na = s1.empty() ? 0 : lyx::atoi(s1);
1110 openNewInset(bv, new InsetFormulaMacro(token(s, ' ', 0), na));
1115 void mathDispatchMathDelim(BufferView * bv, string const & arg)
1117 if (bv->available()) {
1118 if (openNewInset(bv, new InsetFormula))
1119 bv->theLockingInset()->localDispatch(bv, LFUN_MATH_DELIM, arg);
1124 void mathDispatchInsertMatrix(BufferView * bv, string const & arg)
1126 if (bv->available()) {
1127 if (openNewInset(bv, new InsetFormula))
1128 bv->theLockingInset()->localDispatch(bv, LFUN_INSERT_MATRIX, arg);
1132 void mathDispatchInsertMath(BufferView * bv, string const & arg)
1134 if (bv->available()) {
1135 if (arg.size() && arg[0] == '\\') {
1136 InsetFormula * f = new InsetFormula(arg);
1137 openNewInset(bv, f);
1139 mathDispatchMathMode(bv, arg);