# This file is part of lyx2lyx
# -*- coding: utf-8 -*-
-# Copyright (C) 2010 The LyX team
+# Copyright (C) 2011 The LyX team
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
we will handle that properly.
The routine checks to see whether the provided material is
already in the preamble. If not, it adds it.
+ Prepends a comment "% Added by lyx2lyx" to text.
-insert_to_preamble(index, document, text):
+insert_to_preamble(document, text[, index]):
Here, text can be either a single line or a list of lines. It
is bad practice to pass something with embedded newlines, but
we will handle that properly.
- The routine inserts text at document.preamble[index].
+ The routine inserts text at document.preamble[index], where by
+ default index is 0, so the material is inserted at the beginning.
+ Prepends a comment "% Added by lyx2lyx" to text.
put_cmd_in_ert(arg):
Here arg should be a list of strings (lines), which we want to
# This will accept either a list of lines or a single line.
-# It is bad practice to pass something with embedded newlines,
+# It is bad practice to pass something with embedded newlines,
# though we will handle that.
def add_to_preamble(document, text):
" Add text to the preamble if it is not already there. "
if matched:
return
+ document.preamble.extend(["% Added by lyx2lyx"])
document.preamble.extend(text)
# Note that text can be either a list of lines or a single line.
# It should really be a list.
-def insert_to_preamble(index, document, text):
+def insert_to_preamble(document, text, index = 0):
""" Insert text to the preamble at a given line"""
if not type(text) is list:
# it'll give us the one element list we want
# if there's no \n, too
text = text.split('\n')
-
+
+ text.insert(0, "% Added by lyx2lyx")
document.preamble[index:index] = text