]> git.lyx.org Git - features.git/commitdiff
Introduce and use latex_path().
authorAngus Leeming <leeming@lyx.org>
Mon, 18 Apr 2005 17:43:11 +0000 (17:43 +0000)
committerAngus Leeming <leeming@lyx.org>
Mon, 18 Apr 2005 17:43:11 +0000 (17:43 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@9824 a592a061-630c-0410-9148-cb99ea01b6c8

13 files changed:
src/ChangeLog
src/buffer.C
src/insets/ChangeLog
src/insets/ExternalSupport.C
src/insets/ExternalSupport.h
src/insets/insetbibtex.C
src/insets/insetexternal.C
src/insets/insetgraphics.C
src/insets/insetinclude.C
src/support/ChangeLog
src/support/filetools.C
src/support/filetools.h
src/support/os_win32.C

index eab081db17870b6958a3ba3b7e69e1d706eecad8..a0bfb047a5a5486e1739addfda25ca7868067d5e 100644 (file)
@@ -1,3 +1,8 @@
+2005-04-17  Angus Leeming  <leeming@lyx.org>
+
+       * buffer.C (makeLaTeXFile): replace code to manipulate a path
+       containing space and '~' characters with a call to latex_path().
+
 2005-04-17  Angus Leeming  <leeming@lyx.org>
 
        * converter.C (convert): protect all args of convertDefault.sh
index f33c70bbf6dcb629e2bf0dc2b853095f42864342..8f698f51968a1f0af0b3528673a125b46aac5fee 100644 (file)
@@ -98,6 +98,7 @@ using lyx::support::destroyDir;
 using lyx::support::getFormatFromContents;
 using lyx::support::IsDirWriteable;
 using lyx::support::LibFileSearch;
+using lyx::support::latex_path;
 using lyx::support::ltrim;
 using lyx::support::MakeAbsPath;
 using lyx::support::MakeDisplayPath;
@@ -870,10 +871,7 @@ void Buffer::makeLaTeXFile(ostream & os,
                        texrow().newline();
                }
                if (!original_path.empty()) {
-                       string inputpath = os::external_path(original_path);
-                       subst(inputpath, "~", "\\string~");
-                       if (inputpath.find(' ') != string::npos)
-                               inputpath = '"' + inputpath + '"';
+                       string const inputpath = latex_path(original_path);
                        os << "\\makeatletter\n"
                            << "\\def\\input@path{{"
                            << inputpath << "/}}\n"
index 65286e6f270bfdb5d32c6104046f872e3c55fd57..323bbac3866f081fa6a61d5d4b05e54859f8fde0 100644 (file)
@@ -1,3 +1,19 @@
+2005-04-18  Angus Leeming  <leeming@lyx.org>
+
+       * ExternalSupport.[Ch] (doSubstitution): passed an extra boolean
+       'use_latex_path' argument. In turn, passed to the new subst_path
+       function when replacing placeholders with paths.
+       
+       * insetexternal.C (getScreenLabel): 
+       * ExternalSupport.C (lots of places): change invocation of
+       doSubstitution in lots of places, specifying the appropriate values
+       for this 'use_latex_path' boolean.
+
+       * insetbib.C (latex):
+       * insetgraphics.C (latex):
+       * insetinclude.C (latex): pass path to latex_path rather than to
+       os::external_path.
+
 2005-04-18  Martin Vermeer  <martin.vermeer@hut.fi>
 
        * insetcharstyle.C (validate): allow nested charstyle insets
index 5896bdbd2e6b91f5784df663d71bfaca8c1cb09d..a03cb901e5cc3cb8c43cb75b68f0c57b435dd8a4 100644 (file)
@@ -28,6 +28,7 @@
 #include "support/lstrings.h"
 #include "support/lyxalgo.h"
 #include "support/lyxlib.h"
+#include "support/os.h"
 #include "support/package.h"
 #include "support/path.h"
 
@@ -60,9 +61,27 @@ void editExternal(InsetExternalParams const & params, Buffer const & buffer)
 }
 
 
+namespace {
+
+string const subst_path(string const & input,
+                       string const & placeholder,
+                       string const & path,
+                       bool use_latex_path)
+{
+       if (input.find(placeholder) == string::npos)
+               return input;
+       string const path2 = use_latex_path ?
+               support::latex_path(path) : support::os::external_path(path);
+       return support::subst(input, placeholder, path2);
+}
+
+} // namespace anon
+
+
 string const doSubstitution(InsetExternalParams const & params,
                            Buffer const & buffer, string const & s,
-                            bool external_in_tmpdir,
+                            bool use_latex_path,
+                           bool external_in_tmpdir,
                             Substitute what)
 {
        Buffer const * m_buffer = buffer.getMasterBuffer();
@@ -92,35 +111,35 @@ string const doSubstitution(InsetExternalParams const & params,
                if (relToParentPath == "./")
                        relToParentPath.clear();
 
-               result = support::subst(result, "$$FPath", filepath);
-               result = support::subst(result, "$$AbsPath", abspath);
-               result = support::subst(result, "$$RelPathMaster",
-                                       relToMasterPath);
-               result = support::subst(result, "$$RelPathParent",
-                                       relToParentPath);
+               result = subst_path(result, "$$FPath", filepath, use_latex_path);
+               result = subst_path(result, "$$AbsPath", abspath, use_latex_path);
+               result = subst_path(result, "$$RelPathMaster",
+                                   relToMasterPath, use_latex_path);
+               result = subst_path(result, "$$RelPathParent",
+                                   relToParentPath, use_latex_path);
                if (support::AbsolutePath(filename)) {
-                       result = support::subst(result, "$$AbsOrRelPathMaster",
-                                               abspath);
-                       result = support::subst(result, "$$AbsOrRelPathParent",
-                                               abspath);
+                       result = subst_path(result, "$$AbsOrRelPathMaster",
+                                           abspath, use_latex_path);
+                       result = subst_path(result, "$$AbsOrRelPathParent",
+                                           abspath, use_latex_path);
                } else {
-                       result = support::subst(result, "$$AbsOrRelPathMaster",
-                                               relToMasterPath);
-                       result = support::subst(result, "$$AbsOrRelPathParent",
-                                               relToParentPath);
+                       result = subst_path(result, "$$AbsOrRelPathMaster",
+                                           relToMasterPath, use_latex_path);
+                       result = subst_path(result, "$$AbsOrRelPathParent",
+                                           relToParentPath, use_latex_path);
                }
        }
 
        if (what == PATHS)
                return result;
 
-       result = support::subst(result, "$$FName", filename);
-       result = support::subst(result, "$$Basename", basename);
-       result = support::subst(result, "$$Extension",
-                       '.' + support::GetExtension(filename));
-       result = support::subst(result, "$$Tempname", params.tempname());
-       result = support::subst(result, "$$Sysdir",
-                               support::package().system_support());
+       result = subst_path(result, "$$FName", filename, use_latex_path);
+       result = subst_path(result, "$$Basename", basename, use_latex_path);
+       result = subst_path(result, "$$Extension",
+                       '.' + support::GetExtension(filename), use_latex_path);
+       result = subst_path(result, "$$Tempname", params.tempname(), use_latex_path);
+       result = subst_path(result, "$$Sysdir",
+                               support::package().system_support(), use_latex_path);
 
        // Handle the $$Contents(filename) syntax
        if (support::contains(result, "$$Contents(\"")) {
@@ -231,7 +250,7 @@ void updateExternal(InsetExternalParams const & params,
        // the generated file (always in the temp dir)
        string const to_file = doSubstitution(params, buffer,
                                              outputFormat.updateResult,
-                                             true);
+                                             false, true);
        string const abs_to_file =
                support::MakeAbsPath(to_file, m_buffer->temppath());
 
@@ -246,7 +265,7 @@ void updateExternal(InsetExternalParams const & params,
                for (; fit != fend; ++fit) {
                        string const source = support::MakeAbsPath(
                                        doSubstitution(params, buffer, *fit,
-                                                      true),
+                                                      false, true),
                                        m_buffer->temppath());
                        // The path of the referenced file is never the
                        // temp path, but the filename may be the mangled
@@ -254,10 +273,10 @@ void updateExternal(InsetExternalParams const & params,
                        // paths and names separately.
                        string file = support::subst(*fit, "$$FName",
                                        "$$FPath$$Basename$$Extension");
-                       file = doSubstitution(params, buffer, file, false,
+                       file = doSubstitution(params, buffer, file, false, false,
                                              PATHS);
                        file = doSubstitution(params, buffer, file,
-                                             external_in_tmpdir,
+                                             false, external_in_tmpdir,
                                              ALL_BUT_PATHS);
                        // if file is a relative name, it is interpreted
                        // relative to the master document.
@@ -309,8 +328,9 @@ int writeExternal(InsetExternalParams const & params,
 
        updateExternal(params, format, buffer, exportdata, external_in_tmpdir);
 
+       bool const use_latex_path = format == "LaTeX";
        string str = doSubstitution(params, buffer, cit->second.product,
-                                   external_in_tmpdir);
+                                   use_latex_path, external_in_tmpdir);
        str = substituteCommands(params, str, format);
        str = substituteOptions(params, str, format);
        os << str;
index aa6c9894be2e3eb4a861d86fe3829dc25d8d5c82..9967c5dbad49b43eec664f41b7fb01248196ce71 100644 (file)
@@ -50,7 +50,8 @@ enum Substitute {
 std::string const doSubstitution(InsetExternalParams const & params,
                                 Buffer const & buffer,
                                  std::string const & s,
-                                 bool external_in_tmpdir = false,
+                                 bool use_latex_path,
+                                bool external_in_tmpdir = false,
                                  Substitute what = ALL);
 
 
index 73ca790e50296ee3b8f9153b26cc62cb960ae606..7cb57e6686e32bf3e8037751c456c312ecea89cd 100644 (file)
@@ -35,6 +35,7 @@ using lyx::support::ChangeExtension;
 using lyx::support::contains;
 using lyx::support::findtexfile;
 using lyx::support::IsFileReadable;
+using lyx::support::latex_path;
 using lyx::support::ltrim;
 using lyx::support::MakeAbsPath;
 using lyx::support::MakeRelPath;
@@ -132,8 +133,7 @@ int InsetBibtex::latex(Buffer const & buffer, ostream & os,
        // have a comma-separated list of bibliographies
        string db_out;
        while (!adb.empty()) {
-               db_out += os::external_path(normalize_name(buffer, runparams,
-                                                          adb, ".bib"));
+               db_out += latex_path(normalize_name(buffer, runparams, adb, ".bib"));
                db_out += ',';
                db_in = split(db_in, adb,',');
        }
@@ -154,8 +154,7 @@ int InsetBibtex::latex(Buffer const & buffer, ostream & os,
 
        if (!style.empty()) {
                os << "\\bibliographystyle{"
-                  << os::external_path(normalize_name(buffer, runparams,
-                                                      style, ".bst"))
+                  << latex_path(normalize_name(buffer, runparams, style, ".bst"))
                   << "}\n";
                i += 1;
        }
index e985ae175ee8ad2dd82e2a8feb384acb72493391..24885b51786d42c675f70630bd1bca02a83ba1dd 100644 (file)
@@ -562,7 +562,7 @@ string const getScreenLabel(InsetExternalParams const & params,
        if (!ptr)
                return support::bformat(_("External template %1$s is not installed"),
                                        params.templatename());
-       return external::doSubstitution(params, buffer, ptr->guiName);
+       return external::doSubstitution(params, buffer, ptr->guiName, false);
 }
 
 void add_preview_and_start_loading(RenderMonitoredPreview &,
index 10040ab8a4242977f8ed587f6a447078f3186e90..f203b75cf3b70fea8d1944efd146ee58d8f0fffe 100644 (file)
@@ -98,6 +98,7 @@ using lyx::support::FileName;
 using lyx::support::float_equal;
 using lyx::support::GetExtension;
 using lyx::support::IsFileReadable;
+using lyx::support::latex_path;
 using lyx::support::OnlyFilename;
 using lyx::support::rtrim;
 using lyx::support::subst;
@@ -738,12 +739,11 @@ int InsetGraphics::latex(Buffer const & buf, ostream & os,
                << "\tBefore = " << before
                << "\n\tafter = " << after << endl;
 
-
        string latex_str = before + '{';
        // Convert the file if necessary.
        // Remove the extension so LaTeX will use whatever is appropriate
        // (when there are several versions in different formats)
-       latex_str += prepareFile(buf, runparams);
+       latex_str += latex_path(prepareFile(buf, runparams));
        latex_str += '}' + after;
        os << latex_str;
 
index 14f998ad62779ce7a216ca2fcd326682dc2f23e2..ca4a6af20bab402692eb955111818a91696cd7b3 100644 (file)
@@ -62,6 +62,7 @@ using lyx::support::FileName;
 using lyx::support::GetFileContents;
 using lyx::support::IsFileReadable;
 using lyx::support::IsLyXFilename;
+using lyx::support::latex_path;
 using lyx::support::MakeAbsPath;
 using lyx::support::MakeDisplayPath;
 using lyx::support::MakeRelPath;
@@ -385,6 +386,7 @@ int InsetInclude::latex(Buffer const & buffer, ostream & os,
        }
 
        if (isVerbatim(params_)) {
+               incfile = latex_path(incfile);
                os << '\\' << params_.getCmdName() << '{' << incfile << '}';
        } else if (type(params_) == INPUT) {
                runparams.exportdata->addExternalFile("latex", writefile,
@@ -392,10 +394,13 @@ int InsetInclude::latex(Buffer const & buffer, ostream & os,
 
                // \input wants file with extension (default is .tex)
                if (!IsLyXFilename(included_file)) {
+                       incfile = latex_path(incfile);
                        os << '\\' << params_.getCmdName() << '{' << incfile << '}';
                } else {
+               incfile = ChangeExtension(incfile, ".tex");
+               incfile = latex_path(incfile);
                        os << '\\' << params_.getCmdName() << '{'
-                          << ChangeExtension(incfile, ".tex")
+                          << incfile
                           <<  '}';
                }
        } else {
@@ -404,8 +409,10 @@ int InsetInclude::latex(Buffer const & buffer, ostream & os,
 
                // \include don't want extension and demands that the
                // file really have .tex
+               incfile = ChangeExtension(incfile, string());
+               incfile = latex_path(incfile);
                os << '\\' << params_.getCmdName() << '{'
-                  << ChangeExtension(incfile, string())
+                  << incfile
                   << '}';
        }
 
index a4a27f6dc1441ff075eb63c362d5af765fa658e3..07f36f8039d65f11a75be330556696cf8f2f7d0f 100644 (file)
@@ -1,3 +1,14 @@
+ 2005-04-17  Angus Leeming  <leeming@lyx.org>
+       * filetools.C (MakeDisplayPath): invoke os::external_path before
+       returning path.
+
+       * os_win32.C (external_path): convert '/' chars to '\'.
+
+       * filetools.[Ch] (latex_path): new function which modifies
+       an input path containing space and '~' characters into something that
+       LaTeX can understand.
+
 2005-04-17  Angus Leeming  <leeming@lyx.org>
 
        * forkedcall.C (generateChild): do not strip quotes from args on
index 4671f2896097acd415b1450184b60fc06ce92238..ab7a8d34e1404bbb5da6ae955872ced0300c4784 100644 (file)
@@ -83,6 +83,16 @@ bool IsSGMLFilename(string const & filename)
 }
 
 
+string const latex_path(string const & original_path)
+{
+       string path = subst(original_path, "\\", "/");
+       path = subst(path, "~", "\\string~");
+       if (path.find(' ') != string::npos)
+               path = '"' + path + '"';
+       return path;
+}
+
+
 // Substitutes spaces with underscores in filename (and path)
 string const MakeLatexName(string const & file)
 {
@@ -994,7 +1004,7 @@ string const MakeDisplayPath(string const & path, unsigned int threshold)
                str = subst(str, home, "~");
 
        if (str.length() <= threshold)
-               return str;
+               return os::external_path(str);
 
        string const prefix = ".../";
        string temp;
@@ -1015,7 +1025,7 @@ string const MakeDisplayPath(string const & path, unsigned int threshold)
                str = head + "..." + tail;
        }
 
-       return prefix + str;
+       return os::external_path(prefix + str);
 }
 
 
index bdba4bca59af029411e608d6764652f2b6e90088..092aa70a45c3586b8ad3570dc4afc27c05377d4e 100644 (file)
@@ -104,6 +104,19 @@ i18nLibFileSearch(std::string const & dir, std::string const & name,
  */
 std::string const LibScriptSearch(std::string const & command);
 
+/** @param path a file path in internal_path format. Ie, directories
+ *  are indicated by '/', not by '\'.
+ *
+ *  Manipulates @c path into a form suitable for inclusion in a LaTeX
+ *  document.  
+ *  If @c path contains LaTeX special characters, these are escaped.
+ *  Eg, '~' -> '\string~'
+ *  If @c path contains spaces, then the returned path is enclosed in
+ *  "-quotes. This last fix will lead to successful compiliation of the
+ *  LaTeX file only if a sufficiently modern LaTeX compiler is used.
+ */
+std::string const latex_path(std::string const & path);
+
 /// Substitutes active latex characters with underscores in filename
 std::string const MakeLatexName(std::string const & file);
 
index 1559d61e36c1a1cee5bede442e637036782cba3b..711eeb3b94fb176095f1a96120aca3e368f5714d 100644 (file)
@@ -140,10 +140,7 @@ string::size_type common_path(string const & p1, string const & p2)
 
 string external_path(string const & p)
 {
-       string dos_path = p;
-
-       //No backslashes in LaTeX files
-       dos_path = subst(dos_path,'\\','/');
+       string const dos_path = subst(p, "/", "\\");
 
        lyxerr[Debug::LATEX]
                << "<Win32 path correction> ["
@@ -159,7 +156,7 @@ string external_path(string const & p)
 // the Win32/DOS pathnames into Cygwin pathnames.
 string internal_path(string const & p)
 {
-       return subst(p,"\\","/");
+       return subst(p, "\\", "/");
 }