Jean-Marc Lasgouttes wrote: >>>>>>"Herbert" == Herbert Voss <[EMAIL PROTECTED]> writes: >>>>>> > > Herbert> here is a real latex solution for a output when a graphic > Herbert> file doesn't exist. In this case I set the boundingbox to > Herbert> external values and the draft mode. Than we can have any > Herbert> possible filename and need no translation like latexify() or > Herbert> tricks with \verb{}. latex does it all: puts an rectangle > Herbert> with "filename not found" in it. > > THis a great idea... However, could you update the code to either not > add \n in the command or account for them in the return value of the > method (I prefer the first solution). > > As it is, it _seems_ to me (I have not tried it) that it will confuse > the error insets placement.
no, I do not think so, because we return the inserted lines! remember that bug hunting is much more easier when I have an output like \includegraphics[ bb = 0 0 200 100, draft, type=eps]{rose2.eps not found!} and not \includegraphics[bb = 0 0 200 100, draft, type=eps]{rose2.eps not found!} but anyway, here is the patch Herbert -- http://www.lyx.org/help/
Index: src/insets/ChangeLog =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/ChangeLog,v retrieving revision 1.371 diff -u -r1.371 ChangeLog --- src/insets/ChangeLog 27 Mar 2002 12:27:17 -0000 1.371 +++ src/insets/ChangeLog 28 Mar 2002 12:09:46 -0000 @@ -1,3 +1,8 @@ +2002-03-28 Herbert Voss <[EMAIL PROTECTED]> + + * insetgraphic.C: (latex) simplify the code for the latex + output when the file doesn't exist + 2002-03-27 Herbert Voss <[EMAIL PROTECTED]> * insetgraphicsparam.C: change c%, p% to col%, page% Index: src/insets/insetgraphics.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetgraphics.C,v retrieving revision 1.99 diff -u -r1.99 insetgraphics.C --- src/insets/insetgraphics.C 26 Mar 2002 18:20:11 -0000 1.99 +++ src/insets/insetgraphics.C 28 Mar 2002 12:09:46 -0000 @@ -648,71 +648,20 @@ } -namespace { - -string const latexify(string const & str) -{ - ostringstream out; - - string::const_iterator it = str.begin(); - string::const_iterator end = str.end(); - - for (; it != end; ++it) { - switch (*it) { - - case ('$'): - case ('&'): - case ('%'): - case ('#'): - case ('_'): - case ('{'): - case ('}'): - out << '\\' << *it; - break; - - case ('~'): - case ('^'): - out << '\\' << *it << "{}"; - break; - - case ('\\'): - out << "\textbackslash "; - break; - - default: - out << *it; - break; - } - } - - return out.str().c_str(); -} - -} // namespace anon - - int InsetGraphics::latex(Buffer const *buf, ostream & os, bool /*fragile*/, bool/*fs*/) const { - // If there is no file specified, just output a message about it in - // the latex output. - if (params().filename.empty()) { - os << "\\fbox{\\rule[-0.5in]{0pt}{1in}" - << _("empty figure path") << "}\n"; - return 1; // One end-of-line marker added to the stream. - } - - // Enable these helper functions to find the file if it is stored as - // a relative path. - Path p(buf->filePath()); + // If there is no file specified or not existing, + // just output a message about it in the latex output. + lyxerr[Debug::GRAPHICS] << "[latex]filename = " + << params().filename << endl; + string const message = + (IsFileReadable(MakeAbsPath(params().filename, buf->filePath())) + && !params().filename.empty()) ? + string() : + string("bb = 0 0 200 100, draft, type=eps]"); + lyxerr[Debug::GRAPHICS] << "[latex]Messagestring = " << message << endl; + - // Ditto if the file is not there. - if (!IsFileReadable(params().filename)) { - os << "\\fbox{\\rule[-0.5in]{0pt}{1in}" - << latexify(MakeRelPath(params().filename, buf->filePath())) - << _(" not found") << "}\n"; - return 1; // One end-of-line marker added to the stream. - } // These variables collect all the latex code that should be before and // after the actual includegraphics command. string before; @@ -724,15 +673,25 @@ } // We never use the starred form, we use the "clip" option instead. before += "\\includegraphics"; + // Write the options if there are any. string const opts = createLatexOptions(); - if (!opts.empty()) { - before += ("[%\n" + opts +']'); - } + lyxerr[Debug::GRAPHICS] << "[latex]opts = " << opts << endl; + if (!opts.empty() && !message.empty()) + before += ("[" + opts + ',' + message); + else if (!message.empty()) + before += ('[' + message); + else if (!opts.empty()) + before += ("[%" + opts + ']'); + lyxerr[Debug::GRAPHICS] << "[latex]before = " << before << endl; + + lyxerr[Debug::GRAPHICS] << "[latex]after = " << after << endl; + // Make the filename relative to the lyx file // and remove the extension so the LaTeX will use whatever is // appropriate (when there are several versions in different formats) - string const latex_str = before + '{' + prepareFile(buf) + '}' + after; + string const latex_str = message.empty() ? + (before + '{' + prepareFile(buf) + '}' + after) : + (before + '{' + params().filename + " not found!}" + after); os << latex_str; // Return how many newlines we issued.