mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-09 18:31:04 +00:00
Support for \item arguments
This commit is contained in:
parent
662a8907eb
commit
1500e44cba
@ -12,6 +12,15 @@ adjustments are made to tex2lyx and bugs are fixed in lyx2lyx.
|
||||
-----------------------
|
||||
|
||||
|
||||
2012-11-29 Jürgen Spitzmüller <spitz@lyx.org>
|
||||
* Format incremented to 449: Support for \item arguments.
|
||||
Item arguments have the prefix "item:" and a number determining
|
||||
the order.
|
||||
\begin_inset Argument item:1
|
||||
...
|
||||
\end_inset
|
||||
=> \item[...]
|
||||
|
||||
2012-11-25 Kayvan Sylvan <kayvan@sylvan.com>
|
||||
* Format incremented to 448: Change Noweb literate style Scrap
|
||||
to Chunk to be consistent with all the other literate tools
|
||||
|
@ -1,5 +1,5 @@
|
||||
#LyX 2.1 created this file. For more info see http://www.lyx.org/
|
||||
\lyxformat 448
|
||||
\lyxformat 449
|
||||
\begin_document
|
||||
\begin_header
|
||||
\textclass scrbook
|
||||
@ -10815,6 +10815,79 @@ Classic
|
||||
\end_inset
|
||||
|
||||
.
|
||||
\change_inserted 155139281 1354198988
|
||||
|
||||
\end_layout
|
||||
|
||||
\begin_layout Standard
|
||||
|
||||
\change_inserted 155139281 1354199102
|
||||
Arguments for list
|
||||
\begin_inset Flex Code
|
||||
status collapsed
|
||||
|
||||
\begin_layout Plain Layout
|
||||
|
||||
\change_inserted 155139281 1354199013
|
||||
|
||||
\backslash
|
||||
item
|
||||
\change_unchanged
|
||||
|
||||
\end_layout
|
||||
|
||||
\end_inset
|
||||
|
||||
s (as in
|
||||
\begin_inset Flex Code
|
||||
status collapsed
|
||||
|
||||
\begin_layout Plain Layout
|
||||
|
||||
\change_inserted 155139281 1354199102
|
||||
|
||||
\backslash
|
||||
item[foo]
|
||||
\change_unchanged
|
||||
|
||||
\end_layout
|
||||
|
||||
\end_inset
|
||||
|
||||
) have the prefix
|
||||
\begin_inset Flex Code
|
||||
status collapsed
|
||||
|
||||
\begin_layout Plain Layout
|
||||
|
||||
\change_inserted 155139281 1354199044
|
||||
item:
|
||||
\change_unchanged
|
||||
|
||||
\end_layout
|
||||
|
||||
\end_inset
|
||||
|
||||
followed by the number (e.
|
||||
\begin_inset space \thinspace{}
|
||||
\end_inset
|
||||
|
||||
g.
|
||||
|
||||
\begin_inset Flex Code
|
||||
status collapsed
|
||||
|
||||
\begin_layout Plain Layout
|
||||
|
||||
\change_inserted 155139281 1354199064
|
||||
Argument item:1
|
||||
\change_unchanged
|
||||
|
||||
\end_layout
|
||||
|
||||
\end_inset
|
||||
|
||||
)
|
||||
\change_unchanged
|
||||
|
||||
\end_layout
|
||||
|
@ -354,6 +354,10 @@ Style Itemize
|
||||
Align Block
|
||||
AlignPossible Block, Left
|
||||
LabelType Itemize
|
||||
Argument item:1
|
||||
LabelString "Custom Item|s"
|
||||
Tooltip "A customized item string"
|
||||
EndArgument
|
||||
End
|
||||
|
||||
|
||||
@ -373,6 +377,10 @@ Style Enumerate
|
||||
AlignPossible Block, Left
|
||||
LabelType Enumerate
|
||||
RefPrefix enu
|
||||
Argument item:1
|
||||
LabelString "Custom Item|s"
|
||||
Tooltip "A customized item string"
|
||||
EndArgument
|
||||
End
|
||||
|
||||
|
||||
|
@ -163,6 +163,10 @@ Style Enumerate
|
||||
AlignPossible Block, Left
|
||||
LabelType Enumerate
|
||||
RefPrefix enu
|
||||
Argument item:1
|
||||
LabelString "Custom Item|s"
|
||||
Tooltip "A customized item string"
|
||||
EndArgument
|
||||
End
|
||||
|
||||
|
||||
@ -180,6 +184,10 @@ Style Itemize
|
||||
Align Block
|
||||
AlignPossible Block, Left
|
||||
LabelType Itemize
|
||||
Argument item:1
|
||||
LabelString "Custom Item|s"
|
||||
Tooltip "A customized item string"
|
||||
EndArgument
|
||||
End
|
||||
|
||||
|
||||
|
@ -28,6 +28,10 @@ Style Itemize
|
||||
HTMLTag ul
|
||||
HTMLItem li
|
||||
HTMLLabel NONE
|
||||
Argument item:1
|
||||
LabelString "Custom Item|s"
|
||||
Tooltip "A customized item string"
|
||||
EndArgument
|
||||
End
|
||||
|
||||
|
||||
@ -52,6 +56,10 @@ Style Enumerate
|
||||
HTMLItem li
|
||||
HTMLLabel NONE
|
||||
RefPrefix enu
|
||||
Argument item:1
|
||||
LabelString "Custom Item|s"
|
||||
Tooltip "A customized item string"
|
||||
EndArgument
|
||||
End
|
||||
|
||||
Style Description
|
||||
|
@ -25,13 +25,13 @@ import sys, os
|
||||
|
||||
# Uncomment only what you need to import, please.
|
||||
|
||||
from parser_tools import del_token, find_token, find_end_of, find_end_of_inset, \
|
||||
from parser_tools import del_token, find_token, find_token_backwards, find_end_of, find_end_of_inset, \
|
||||
find_end_of_layout, find_re, get_option_value, get_value, get_quoted_value, \
|
||||
set_option_value
|
||||
|
||||
#from parser_tools import find_token, find_end_of, find_tokens, \
|
||||
#find_token_exact, find_end_of_inset, find_end_of_layout, \
|
||||
#find_token_backwards, is_in_inset, del_token, check_token
|
||||
#is_in_inset, del_token, check_token
|
||||
|
||||
from lyx2lyx_tools import add_to_preamble, put_cmd_in_ert, get_ert
|
||||
|
||||
@ -1232,7 +1232,7 @@ def revert_IEEEtran(document):
|
||||
def convert_Argument_to_TeX_brace(document, line, n, nmax, environment):
|
||||
'''
|
||||
Converts TeX code to an InsetArgument
|
||||
!!! Be careful if the braces are different in your case as exppected here:
|
||||
!!! Be careful if the braces are different in your case as expected here:
|
||||
- }{ separates mandatory arguments of commands
|
||||
- { and } surround a mandatory argument of an environment
|
||||
usage:
|
||||
@ -1429,6 +1429,23 @@ def convert_literate(document):
|
||||
document.body[i] = "\\begin_layout Chunk"
|
||||
i = i + 1
|
||||
|
||||
def revert_itemargs(document):
|
||||
" Reverts \\item arguments to TeX-code "
|
||||
while True:
|
||||
i = find_token(document.body, "\\begin_inset Argument item:", 0)
|
||||
j = find_end_of_inset(document.body, i)
|
||||
if i == -1:
|
||||
break
|
||||
lastlay = find_token_backwards(document.body, "\\begin_layout", i)
|
||||
beginPlain = find_token(document.body, "\\begin_layout Plain Layout", i)
|
||||
endLayout = find_token(document.body, "\\end_layout", beginPlain)
|
||||
endInset = find_token(document.body, "\\end_inset", endLayout)
|
||||
content = document.body[beginPlain + 1 : endLayout]
|
||||
del document.body[i:j+1]
|
||||
subst = put_cmd_in_ert("[") + content + put_cmd_in_ert("]")
|
||||
document.body[lastlay + 1:lastlay + 1] = subst
|
||||
i = i + 1
|
||||
|
||||
##
|
||||
# Conversion hub
|
||||
#
|
||||
@ -1469,10 +1486,12 @@ convert = [
|
||||
[445, []],
|
||||
[446, [convert_latexargs]],
|
||||
[447, [convert_IEEEtran, convert_AASTeX, convert_AGUTeX, convert_IJMP]],
|
||||
[448, [convert_literate]]
|
||||
[448, [convert_literate]],
|
||||
[449, []]
|
||||
]
|
||||
|
||||
revert = [
|
||||
[448, [revert_itemargs]],
|
||||
[447, [revert_literate]],
|
||||
[446, [revert_IEEEtran, revert_AASTeX, revert_AGUTeX, revert_IJMP]],
|
||||
[445, [revert_latexargs]],
|
||||
|
@ -322,8 +322,10 @@ bool Layout::read(Lexer & lex, TextClass const & tclass)
|
||||
case LT_RESETARGS:
|
||||
bool reset;
|
||||
lex >> reset;
|
||||
if (reset)
|
||||
if (reset) {
|
||||
latexargs_.clear();
|
||||
itemargs_.clear();
|
||||
}
|
||||
break;
|
||||
|
||||
case LT_ARGUMENT:
|
||||
@ -879,8 +881,10 @@ void Layout::readArgument(Lexer & lex)
|
||||
bool finished = false;
|
||||
arg.font = inherit_font;
|
||||
arg.labelfont = inherit_font;
|
||||
unsigned int nr;
|
||||
lex >> nr;
|
||||
string id;
|
||||
lex >> id;
|
||||
bool const itemarg = prefixIs(id, "item:");
|
||||
|
||||
while (!finished && lex.isOK() && !error) {
|
||||
lex.next();
|
||||
string const tok = ascii_lowercase(lex.getString());
|
||||
@ -921,8 +925,10 @@ void Layout::readArgument(Lexer & lex)
|
||||
}
|
||||
if (arg.labelstring.empty())
|
||||
LYXERR0("Incomplete Argument definition!");
|
||||
else if (itemarg)
|
||||
itemargs_[id] = arg;
|
||||
else
|
||||
latexargs_[nr] = arg;
|
||||
latexargs_[id] = arg;
|
||||
}
|
||||
|
||||
|
||||
|
@ -100,10 +100,12 @@ public:
|
||||
FontInfo labelfont;
|
||||
};
|
||||
///
|
||||
typedef std::map<unsigned int, latexarg> LaTeXArgMap;
|
||||
typedef std::map<std::string, latexarg> LaTeXArgMap;
|
||||
///
|
||||
LaTeXArgMap const & latexargs() const { return latexargs_; }
|
||||
///
|
||||
LaTeXArgMap const & itemargs() const { return itemargs_; }
|
||||
///
|
||||
int optArgs() const;
|
||||
///
|
||||
int requiredArgs() const;
|
||||
@ -399,6 +401,8 @@ private:
|
||||
std::set<std::string> requires_;
|
||||
///
|
||||
LaTeXArgMap latexargs_;
|
||||
///
|
||||
LaTeXArgMap itemargs_;
|
||||
};
|
||||
|
||||
} // namespace lyx
|
||||
|
@ -2526,8 +2526,11 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
|
||||
}
|
||||
Layout const & lay = cur.paragraph().layout();
|
||||
Layout::LaTeXArgMap args = lay.latexargs();
|
||||
Layout::LaTeXArgMap itemargs = lay.itemargs();
|
||||
if (!itemargs.empty())
|
||||
args.insert(itemargs.begin(), itemargs.end());
|
||||
Layout::LaTeXArgMap::const_iterator const lait =
|
||||
args.find(convert<unsigned int>(arg));
|
||||
args.find(arg);
|
||||
if (lait != args.end()) {
|
||||
enable = true;
|
||||
InsetList::const_iterator it = cur.paragraph().insetList().begin();
|
||||
|
@ -1555,10 +1555,15 @@ void MenuDefinition::expandArguments(BufferView const * bv, bool switcharg)
|
||||
|
||||
Inset const * inset = &bv->cursor().inset();
|
||||
Layout::LaTeXArgMap args;
|
||||
if (inset && bv->cursor().paragraph().layout().latexargs().empty())
|
||||
if (inset && bv->cursor().paragraph().layout().latexargs().empty()
|
||||
&& bv->cursor().paragraph().layout().itemargs().empty())
|
||||
args = inset->getLayout().latexargs();
|
||||
else
|
||||
else {
|
||||
args = bv->cursor().paragraph().layout().latexargs();
|
||||
Layout::LaTeXArgMap itemargs = bv->cursor().paragraph().layout().itemargs();
|
||||
if (!itemargs.empty())
|
||||
args.insert(itemargs.begin(), itemargs.end());
|
||||
}
|
||||
if (args.empty() || (switcharg && args.size() == 1))
|
||||
return;
|
||||
Layout::LaTeXArgMap::const_iterator lait = args.begin();
|
||||
@ -1570,11 +1575,11 @@ void MenuDefinition::expandArguments(BufferView const * bv, bool switcharg)
|
||||
add(MenuItem(MenuItem::Command, item,
|
||||
FuncRequest(LFUN_INSET_MODIFY,
|
||||
from_ascii("changetype ")
|
||||
+ convert<docstring>((*lait).first))));
|
||||
+ from_ascii((*lait).first))));
|
||||
else
|
||||
add(MenuItem(MenuItem::Command, item,
|
||||
FuncRequest(LFUN_ARGUMENT_INSERT,
|
||||
convert<docstring>((*lait).first))));
|
||||
from_ascii((*lait).first))));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -58,12 +58,16 @@ void InsetArgument::read(Lexer & lex)
|
||||
void InsetArgument::updateBuffer(ParIterator const & it, UpdateType utype)
|
||||
{
|
||||
Layout::LaTeXArgMap args;
|
||||
bool const insetlayout = &it.inset() && it.paragraph().layout().latexargs().empty();
|
||||
bool const insetlayout = &it.inset() && it.paragraph().layout().latexargs().empty()
|
||||
&& it.paragraph().layout().itemargs().empty();
|
||||
if (insetlayout) {
|
||||
args = it.inset().getLayout().latexargs();
|
||||
pass_thru_ = it.inset().getLayout().isPassThru();
|
||||
} else {
|
||||
args = it.paragraph().layout().latexargs();
|
||||
Layout::LaTeXArgMap itemargs = it.paragraph().layout().itemargs();
|
||||
if (!itemargs.empty())
|
||||
args.insert(itemargs.begin(), itemargs.end());
|
||||
pass_thru_ = it.paragraph().layout().pass_thru;
|
||||
}
|
||||
|
||||
@ -102,8 +106,7 @@ void InsetArgument::updateBuffer(ParIterator const & it, UpdateType utype)
|
||||
name_ = convert<string>(ours);
|
||||
}
|
||||
}
|
||||
Layout::LaTeXArgMap::const_iterator const lait =
|
||||
args.find(convert<unsigned int>(name_));
|
||||
Layout::LaTeXArgMap::const_iterator const lait = args.find(name_);
|
||||
if (lait != args.end()) {
|
||||
docstring label = translateIfPossible((*lait).second.labelstring);
|
||||
docstring striplabel;
|
||||
@ -179,8 +182,7 @@ bool InsetArgument::getStatus(Cursor & cur, FuncRequest const & cmd,
|
||||
args = cur.inset().getLayout().latexargs();
|
||||
else
|
||||
args = cur.paragraph().layout().latexargs();
|
||||
Layout::LaTeXArgMap::const_iterator const lait =
|
||||
args.find(convert<unsigned int>(type));
|
||||
Layout::LaTeXArgMap::const_iterator const lait = args.find(type);
|
||||
if (lait != args.end()) {
|
||||
flag.setEnabled(true);
|
||||
InsetList::const_iterator it = cur.paragraph().insetList().begin();
|
||||
|
@ -503,7 +503,7 @@ void InsetLayout::readArgument(Lexer & lex)
|
||||
bool finished = false;
|
||||
arg.font = inherit_font;
|
||||
arg.labelfont = inherit_font;
|
||||
unsigned int nr;
|
||||
string nr;
|
||||
lex >> nr;
|
||||
while (!finished && lex.isOK() && !error) {
|
||||
lex.next();
|
||||
|
@ -338,11 +338,11 @@ bool InsetText::getStatus(Cursor & cur, FuncRequest const & cmd,
|
||||
status.setEnabled(false);
|
||||
return true;
|
||||
}
|
||||
if (&buffer().inset() == this || !cur.paragraph().layout().latexargs().empty())
|
||||
if (&buffer().inset() == this || !cur.paragraph().layout().latexargs().empty()
|
||||
|| !cur.paragraph().layout().itemargs().empty())
|
||||
return text_.getStatus(cur, cmd, status);
|
||||
Layout::LaTeXArgMap args = getLayout().latexargs();
|
||||
Layout::LaTeXArgMap::const_iterator const lait =
|
||||
args.find(convert<unsigned int>(arg));
|
||||
Layout::LaTeXArgMap::const_iterator const lait = args.find(arg);
|
||||
if (lait != args.end()) {
|
||||
status.setEnabled(true);
|
||||
InsetList::const_iterator it = cur.paragraph().insetList().begin();
|
||||
|
@ -316,7 +316,7 @@ void TeXEnvironment(Buffer const & buf, Text const & text,
|
||||
|
||||
|
||||
void latexArgInsets(Paragraph const & par, otexstream & os,
|
||||
OutputParams const & runparams, Layout::LaTeXArgMap const & latexargs)
|
||||
OutputParams const & runparams, Layout::LaTeXArgMap const & latexargs, bool item)
|
||||
{
|
||||
map<int, InsetArgument const *> ilist;
|
||||
vector<string> required;
|
||||
@ -330,10 +330,11 @@ void latexArgInsets(Paragraph const & par, otexstream & os,
|
||||
if (ins->name().empty())
|
||||
LYXERR0("Error: Unnamed argument inset!");
|
||||
else {
|
||||
unsigned int const nr = convert<unsigned int>(ins->name());
|
||||
string const name = item ? split(ins->name(), ':') : ins->name();
|
||||
unsigned int const nr = convert<unsigned int>(name);
|
||||
ilist[nr] = ins;
|
||||
Layout::LaTeXArgMap::const_iterator const lit =
|
||||
latexargs.find(nr);
|
||||
latexargs.find(ins->name());
|
||||
if (lit != latexargs.end()) {
|
||||
Layout::latexarg const & arg = (*lit).second;
|
||||
if (!arg.requires.empty()) {
|
||||
@ -356,7 +357,7 @@ void latexArgInsets(Paragraph const & par, otexstream & os,
|
||||
InsetArgument const * ins = (*lit).second;
|
||||
if (ins) {
|
||||
Layout::LaTeXArgMap::const_iterator const lait =
|
||||
latexargs.find(convert<unsigned int>(ins->name()));
|
||||
latexargs.find(ins->name());
|
||||
if (lait != latexargs.end()) {
|
||||
Layout::latexarg arg = (*lait).second;
|
||||
docstring ldelim = arg.mandatory ?
|
||||
@ -376,7 +377,8 @@ void latexArgInsets(Paragraph const & par, otexstream & os,
|
||||
Layout::LaTeXArgMap::const_iterator lait = latexargs.begin();
|
||||
Layout::LaTeXArgMap::const_iterator const laend = latexargs.end();
|
||||
for (; lait != laend; ++lait) {
|
||||
if ((*lait).first == i) {
|
||||
string const name = item ? "item:" + convert<string>(i) : convert<string>(i);
|
||||
if ((*lait).first == name) {
|
||||
Layout::latexarg arg = (*lait).second;
|
||||
if (arg.mandatory) {
|
||||
docstring ldelim = arg.ldelim.empty() ?
|
||||
@ -385,7 +387,7 @@ void latexArgInsets(Paragraph const & par, otexstream & os,
|
||||
from_ascii("}") : arg.rdelim;
|
||||
os << ldelim << rdelim;
|
||||
} else if (find(required.begin(), required.end(),
|
||||
convert<string>((*lait).first)) != required.end()) {
|
||||
(*lait).first) != required.end()) {
|
||||
docstring ldelim = arg.ldelim.empty() ?
|
||||
from_ascii("[") : arg.ldelim;
|
||||
docstring rdelim = arg.rdelim.empty() ?
|
||||
@ -409,14 +411,18 @@ void parStartCommand(Paragraph const & par, otexstream & os,
|
||||
case LATEX_COMMAND:
|
||||
os << '\\' << from_ascii(style.latexname());
|
||||
|
||||
// Separate handling of optional argument inset.
|
||||
// Command arguments
|
||||
if (!style.latexargs().empty())
|
||||
latexArgInsets(par, os, runparams, style.latexargs());
|
||||
os << from_ascii(style.latexparam());
|
||||
break;
|
||||
case LATEX_ITEM_ENVIRONMENT:
|
||||
case LATEX_LIST_ENVIRONMENT:
|
||||
os << "\\item ";
|
||||
os << "\\item";
|
||||
// Item arguments
|
||||
if (!style.itemargs().empty())
|
||||
latexArgInsets(par, os, runparams, style.itemargs(), true);
|
||||
os << " ";
|
||||
break;
|
||||
case LATEX_BIB_ENVIRONMENT:
|
||||
// ignore this, the inset will write itself
|
||||
|
@ -38,7 +38,7 @@ class Text;
|
||||
/// must all come first.
|
||||
void latexArgInsets(Paragraph const & par,
|
||||
otexstream & os, OutputParams const & runparams,
|
||||
Layout::LaTeXArgMap const & latexargs);
|
||||
Layout::LaTeXArgMap const & latexargs, bool item = false);
|
||||
|
||||
/** Export \p paragraphs of buffer \p buf to LaTeX.
|
||||
Don't use a temporary stringstream for \p os if the final output is
|
||||
|
@ -80,6 +80,10 @@ Format LaTeX feature LyX feature
|
||||
\renewcommand{\sffamily}{uop}
|
||||
446 Optional and required arguments InsetArgument
|
||||
now numbered by order
|
||||
447
|
||||
448
|
||||
449 \item[<arg>] \begin_inset Argument item:<nr>
|
||||
|
||||
|
||||
|
||||
General
|
||||
|
@ -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 448 // kayvan: fix for noweb literate docs
|
||||
#define LYX_FORMAT_TEX2LYX 448
|
||||
#define LYX_FORMAT_LYX 449 // spitz: support for \item arguments
|
||||
#define LYX_FORMAT_TEX2LYX 449 // spitz: support for \item arguments
|
||||
|
||||
#if LYX_FORMAT_TEX2LYX != LYX_FORMAT_LYX
|
||||
#ifndef _MSC_VER
|
||||
|
Loading…
Reference in New Issue
Block a user