- file.body[i] = file.body[i] + '}'
- i = i + 1
- file.body[i:i] = ['', '\\end_inset']
- i = i + 2
- j = find_end_of_inset(file.body, i)
- if j == -1:
- file.warning("Malformed LyX file: Missing '\\end_inset'.")
- break
- file.body[j-1:j-1] = ['\\begin_inset ERT', 'status ' + params['collapsed'],
- '', '\\layout Standard', '']
- j = j + 4
- if params['use_parbox'] == '1':
- file.body.insert(j, '}')
- else:
- file.body[j:j] = ['\\backslash ', 'end{minipage}']
+ ert = '\\begin{lyxtolyxrealminipage}'
+
+ # convert optional arguments only if not latex default
+ if (pos[params['position']] != 'c' or
+ inner_pos[params['inner_pos']] != pos[params['position']] or
+ params['height_special'] != 'totalheight' or
+ len2value(params['height']) != 1.0):
+ ert = ert + '[' + pos[params['position']] + ']'
+ if (inner_pos[params['inner_pos']] != pos[params['position']] or
+ params['height_special'] != 'totalheight' or
+ len2value(params['height']) != 1.0):
+ ert = ert + '[' + convert_len(params['height'],
+ params['height_special']) + ']'
+ if inner_pos[params['inner_pos']] != pos[params['position']]:
+ ert = ert + '[' + inner_pos[params['inner_pos']] + ']'
+
+ ert = ert + '{' + convert_len(params['width'],
+ params['special']) + '}'
+
+ if params['use_parbox'] != '0':
+ ert = ert + '{'
+ ert = ert + '\\let\\minipage\\lyxtolyxminipage%\n'
+ ert = ert + '\\let\\endminipage\\endlyxtolyxminipage%\n'
+
+ old_i = i
+ i = insert_ert(file.body, i, 'Collapsed', ert)
+ j = j + i - old_i - 1
+
+ file.body[i:i] = ['\\begin_inset Minipage',
+ 'position %d' % params['position'],
+ 'inner_position 1',
+ 'height "1in"',
+ 'width "' + params['width'] + '"',
+ 'collapsed ' + params['collapsed']]
+ i = i + 6
+ j = j + 6
+
+ # Restore the original minipage environment since we may have
+ # minipages inside this box.
+ # Start a new paragraph because the following may be nonstandard
+ file.body[i:i] = ['\\layout Standard', '', '']
+ i = i + 2
+ j = j + 3
+ ert = '\\let\\minipage\\lyxtolyxrealminipage%\n'
+ ert = ert + '\\let\\endminipage\\lyxtolyxrealendminipage%'
+ old_i = i
+ i = insert_ert(file.body, i, 'Collapsed', ert)
+ j = j + i - old_i - 1
+
+ # Redefine the minipage end before the inset end.
+ # Start a new paragraph because the previous may be nonstandard
+ file.body[j:j] = ['\\layout Standard', '', '']
+ j = j + 2
+ ert = '\\let\\endminipage\\endlyxtolyxminipage'
+ j = insert_ert(file.body, j, 'Collapsed', ert)
+ j = j + 1
+ file.body.insert(j, '')
+ j = j + 1
+
+ # LyX writes '%\n' after each box. Therefore we need to end our
+ # ERT with '%\n', too, since this may swallow a following space.
+ if params['use_parbox'] != '0':
+ ert = '}%\n'
+ else:
+ ert = '\\end{lyxtolyxrealminipage}%\n'
+ j = insert_ert(file.body, j, 'Collapsed', ert)
+
+ # We don't need to restore the original minipage after the inset
+ # end because the scope of the redefinition is the original box.
+