# Trying to achieve the Word equivalent of “style for following paragraph”

In MSWord, when defining a paragraph style, it's possible to define the style of the following paragraph (the style that will chosen when I type return after entering the text of the style). This is practical, since some paragraphs such as headings are followed by normal style, whereas numbered lists are followed by the same list style.

In LyX I'm using a customized .layout for the Exam class in LaTeX. Ultimately the LaTeX has to look something like:

\begin{questions}
\question[2]
\question[2]
What is the air-speed velocity of an unladen swallow?
...
\end{questions}


I've defined a Flex inset for the questions environment as:

InsetLayout "Flex:Questions"
LabelFont
Family Sans
Series Bold
EndFont
Decoration  Classic
BgColor insetbg
LyxType Custom
LatexName   questions
LatexType   Environment
LabelString "Questions block"
ResetsFont true
End


Then I'm entering \questions by selecting the Question style in the drop-down menu. It is defined as follows:

Style Question
CopyStyle       Enumerate
LatexType       Command
LeftMargin      "MM"
LatexName       question
ParSkip         0.4
Align           Left
LabelType       Static
LabelCounter    questionnumber
LabelString     "\arabic{questionnumber}."
Category        Questions
Argument        1
LabelString "Points"
Tooltip     "Number of points, e.g., 1, 2, 5, "
AutoInsert  1
EndArgument
End


Everything works. However, I'm trying to tweak it so that after pressing Return at the end of a question, the next paragraph's style is also the same as the last (e.g., Question). I'd like to set this up for all the question-related styles, e.g., \part, \subpart, etc., which all have their respective environment (like \begin{questions} .. \end{questions}. Also, \choice and/or \CorrectChoice are styles I'd like to work this way in the \begin{choices} environment.

I saw the support for LatexType Item_Environment in styles, but it seems it only adds \items for each entry. I couldn't find a way to customize this so it adds a specific style, e.g., \question. Is there a way to achieve this in LyX?

Edit I'm using LyX 2.1.3 under Windows (7 and 8.1).

• What happens if you do "alt + p, <Return>" instead of just <Return>? Does that do what you want? For example, if you ware in an enumerate and you have 1. first item 2. second item 3. third item, then do alt + p, <Return> you will have 1. first item. – scottkosty Jul 18 '15 at 17:16
• TeX/LaTeX model is completely different. There's no concept of “style for the next paragraph”. – egreg Jul 18 '15 at 20:26
• @Fuhrmanator I'm not sure that is true. If it is true, I'd say LyX ought to be considered off-topic here. However, I don't think it is. The underlying formatting is LaTeX and, as I understand it, it is difficult to use LyX effectively without some understanding of how LateX does things. (Not to say it isn't relatively easy to use without this - but that using it effectively to achieve customised formatting depends on an understanding of the underlying formatting.) So there is no reason to expect a Word function to make any sense as a LyX function because often it will not do so at all. – cfr Jul 19 '15 at 3:03
• I'm voting to close this question as off-topic because it is a request for a new feature in lyx. – Mico Jul 19 '15 at 3:11
• No, I wasn't accusing you of such. :) But if it's not possible to do something, that doesn't make it a feature request. Surely an answer of "No it's not possible to do this because..." is a good answer. We have plenty similar answers on the site for other such questions. (e.g. editor features that people ask about.) – Alan Munn Jul 19 '15 at 14:06

This isn't possible with a Flex inset, but it is possible with a list, as Jurgen Spitzmuller points out over on lyx-users.

Style Questions
Margin           Static
LatexType        Item_Environment
LatexName        questions
ItemCommand      question
Argument item:1
LabelString    "Points"
EndArgument
LeftMargin       MMN
LabelSep         xx
LabelType        Enumerate
End


The key is the ItemCommand, which tells LyX what command to use for items in the environment. (Default, of course, is \item.)

Still, I think it's a natural idea to have a "next style" command for all kinds of layouts. Basically, what LyX does now is use the DefaultStyle, unless the current layout is an environment, in which case it uses the same style.

• Welcome to TeX.sx (although you've been registered for a while). It's really nice to have your expertise on the site for LyX questions in particular, because due to the small number of LyX users here LyX questions often don't get the kinds of answers they deserve. – Alan Munn Jul 19 '15 at 18:40
• I played with this and it's interesting (I was focusing too much on flex insets because of nesting). Even the "increase depth" could be useful. However, I can't see a way to customize a separate environment for the lower depth, which changes in exam.cls, e.g., questions > parts > subparts > subsubparts). I think I must use flex insets because of this constraint, although I should have put this in my question. Also, the choices environment can be nested anywhere within this hierarchy. – Fuhrmanator Jul 19 '15 at 19:47
• If you refer to what is demonstrated in sec 4.2 of the exam manual: I do not see why this should not be possible with the style approach. – JSpitzm Jul 19 '15 at 20:10
• @JSpitzm Indeed, I did a quick test and nesting as shown in sec 4.2 works, provided one 1) chooses Increase depth and 2) changes the layout to the appropriate nested style. It would be beneficial if LyX could get hints from the layout to aim the user in the right direction of the nesting hierarchy with a style sequence (e.g., if I'm in Questions and I do increase depth, LyX could automatically switch to Parts). – Fuhrmanator Jul 19 '15 at 22:58
• Thanks again for the advice. Now it seems it's not adequate because several exam environments have alternates for ItemCommand. The bonus feature from sec 4.6 applies to questions, parts, subparts, subsubparts, and it means you can have e.g. \question or \bonusquestion within questions environment. A similar situation arrives with choices environment which allows \choice and \CorrectChoice. I'm not seeing how this approach can allow this. – Fuhrmanator Jul 19 '15 at 23:33