Bo Peng wrote:
Richard claimed that his bundling method does not have the filename in
.lyx file issue, is easy, less intrusive and have no trouble in
unbundling. Fortunately, while I was not able to compare my previous
approach to air last time, he has partially implemented his method in
his personal branch so that I can have a look at his code this time.
Since he is too busy to summarize what he is doing, allow me to try my
best and please forgive my potentially wrong interpretation.
Richard's approach is characterized by a 'copy to a subdirectory
filename.lyxdir' action. When lyx is working in 'bundled' mode, all
inserted files are copied to a pre-specified directory under a
directory filename.lyxdir. For example, if you insert
../figures/file.png, it will appear as
mylyfile.lyxdir/graphics/file.png. When you switch off this 'bundled'
mode, things turns to normal. It does not appear to me that this
method is intended to make any file format change, but Richard stated
in his svn log that he may zip mylyxfile.lyx with mylyxfile.lyxdir so
that his bundled format is a zip format.
This is all more or less correct, but bundling is separate from
compressing. Bundled mode doesn't involve any file format change, except
for a buffer parameter flag (\bundled). It is important to understand
this, as many of the remarks made below have to do with the "*.lyz"
business. This has nothing to do with my approach.
The thought was just that, if you turn on compression AS WELL AS
bundling, then you should get a zip of the whole thing, and then it
should be possible to open this "*.lyz" file in LyX and work with it.
But this isn't implemented, and it isn't a file format change in any
interesting sense. We already have compressed files. There's no reason
we can't add the "bundle directory" to the zip.
From what I have read, his approach should work like this:
1. Users work as usual in unbundled mode.
Users work in whichever mode they wish.
2. When the document is turned to 'bundled' mode, a directory
filename.lyxdir is created in the document directory. All external
files are copied to this directory. Note that even files in the
document directory are copied.
3. In the 'bundled' mode, insert ../figures/file.png will be inserted
as filename.lyxdir/figures/file.png, subject to filename changes to
avoid filename conflict.
This is all there is to my implementation. Turning on the "bundle" flag
simply turns on the behavior described in (2) and (3). That's all.
That's why the code is so simple. Conceptually, bundled mode does
nothing but copy the files for the user into a subdirectory of the
document directory, in a way that is transparent and, so far as I can
see, essentially identical to what OOo does. All the criticisms below
apply equally, so far as I can see, to OOo's behavior, then. Except that
OOo doesn't allow "update from external file", which I do---though that
isn't as yet implemented.
4. When users save in 'bundled' mode, filename.lyx is zipped with
filename.lyxdir, to possibly to another file named filename.lyz. (I am
not sure).
Saving in bundled mode is no different from saving in normal mode,
unless compression is on.
5. If a user turns off 'bundled' mode, things go back to normal (files
are not copied back). Saving a file in unbundled mode will save in
plain text format.
6. When filename.lyz is opened, filename.lyxdir is created and users
would work in the 'bundled' mode.
Again, this isn't right, since the .lyz business is optional. Opening a
bundled file is exactly like opening a normal file, or like opening a
compressed file, depending.
He sketched this method a while ago. I objected it without a second
thought and I will certainly object it this time. However, I guess I
need to explain why I dislike this idea because it was liked by some
developers.
1, This method is more intrusive than my approach, both in
user-interaction and in file format.
In my approach, users select 'embed', and the file is embedded. There
is no change in user-interaction. The file format change is minimal
because only the embed lines and the extra begin/end_embedded_files
section need to be handled in lyx2lyx. The file itself is still in
plain text format.
In Richard's approach, the same insert action would lead to different
results, depending on which 'mode' the document is in. The file format
is now either a directory with pre-specified structure, or a zip file.
In my approach, there is absolutely no file format change, except for a
buffer parameter flag. The directory is just that: a directory. And yes,
of course what happens depends upon which mode you are in. The same
would be true in Bo's approach if it were based on a "bundled mode"
rather than "selective embedding". I go for the former, for reasons much
discussed elsewhere.
2. I dislike the idea of a pre-specified directory structure. Why
should filename.lyxdir/graphics, filename.lyxdir/bib is clearer than
my chapter1/figure1_1.png..., chapter2/figure2_1,
../all_my_bibs/mybib.bib structure?
The directory structure is internal to LyX and not something the user
has to deal with. It's comparable to how OOo internally stores graphics,
etc.
If we wanted, we could allow the user to create arbitrary directories
inside filename.lyxdir/, and files placed there wouldn't be moved. This
may already be how my code behaves. But if not, then it'd be trivial to
make it behave that way. I don't see the point of this, though.
3. This method disallows the use of out of tree files, thus disallow
the sharing of external files between different .lyx files.
Yes, it does. This is a consequence of there not being selective
embedding. That is a different discussion, one that continues with words
like "session-based alternative".
4. The switching between bundle and unbundled mode is non-reversible.
For example, when ../figures/figure.png is copied to
filename.lyxdir/figures/figure.png during bundling, it is not copied
back during unbundling. That is to say, if you work in unbundled mode
locally, send your document in bundled mode to your co-author, you can
not get your external files back when the document is sent back. In
another word, you have to use bundled mode if you intent to share your
file with others.
This discussion would also involve the words "session-based alternative".
5. This method disallows the use of external file in bundled mode. All
files are embedded. For example, when I insert ../figures/figure.png,
updating this file will not change the document output. Then, a user
might want to 'unbundle' the document to make his updated figure work.
No, it will not because the inserted file is still
filename.lyxdir/graphics/figure.png, not ../figures/figure.png.
This discussion too would involve the words "session-based alternative".
Richard