mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-13 17:20:55 +00:00
Introduce and use latex_path().
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/branches/BRANCH_1_3_X@9825 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
fe987ccd7f
commit
b5fd3b6d0d
@ -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-03-30 Jean-Marc Lasgouttes <lasgouttes@lyx.org>
|
||||
|
||||
* lyxfunc.C (dispatch): translate message before sending it to the
|
||||
|
@ -1742,10 +1742,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"
|
||||
|
@ -1,3 +1,16 @@
|
||||
2005-04-17 Angus Leeming <leeming@lyx.org>
|
||||
|
||||
* insetbib.C (latex):
|
||||
* insetgraphics.C (latex):
|
||||
* insetinclude.C (latex): pass path to latex_path rather than to
|
||||
os::external_path.
|
||||
|
||||
* insetexternal.[Ch] (doSubstitution, subst_path): pass all paths to
|
||||
os::external_path or to latex_path, dependent on a new boolean
|
||||
'use_latex_path' argument to the function.
|
||||
Change invocation of doSubstitution in lots of places, specifying
|
||||
the appropriate values for this boolean.
|
||||
|
||||
2005-04-17 Angus Leeming <leeming@lyx.org>
|
||||
|
||||
* insetgraphics.C (prepareFile): protect all args of convertDefault.sh
|
||||
|
@ -179,7 +179,7 @@ int InsetBibtex::latex(Buffer const * buffer, ostream & os,
|
||||
|
||||
if (!style.empty()) { // we want no \biblio...{}
|
||||
os << "\\bibliographystyle{"
|
||||
<< os::external_path(normalize_name(buffer, style, ".bst"))
|
||||
<< latex_path(normalize_name(buffer, style, ".bst"))
|
||||
<< "}\n";
|
||||
}
|
||||
|
||||
@ -216,8 +216,7 @@ int InsetBibtex::latex(Buffer const * buffer, ostream & os,
|
||||
string db_in = getContents();
|
||||
db_in = split(db_in, adb, ',');
|
||||
while (!adb.empty()) {
|
||||
db_out += os::external_path(normalize_name(buffer,
|
||||
adb, ".bib"));
|
||||
db_out += latex_path(normalize_name(buffer, adb, ".bib"));
|
||||
db_out += ',';
|
||||
db_in= split(db_in, adb,',');
|
||||
}
|
||||
|
@ -27,6 +27,7 @@
|
||||
#include "support/forkedcall.h"
|
||||
#include "support/lstrings.h"
|
||||
#include "support/lyxalgo.h"
|
||||
#include "support/os.h"
|
||||
#include "support/package.h"
|
||||
#include "support/path.h"
|
||||
|
||||
@ -72,7 +73,7 @@ void InsetExternal::setFromParams(Params const & p)
|
||||
|
||||
string const InsetExternal::editMessage() const
|
||||
{
|
||||
return doSubstitution(0, params_.templ.guiName);
|
||||
return doSubstitution(0, params_.templ.guiName, false);
|
||||
}
|
||||
|
||||
|
||||
@ -147,7 +148,9 @@ int InsetExternal::write(string const & format,
|
||||
}
|
||||
|
||||
updateExternal(format, buf);
|
||||
string const outstring = doSubstitution(buf, cit->second.product);
|
||||
bool const use_latex_path = format == "LaTeX";
|
||||
string const outstring = doSubstitution(buf, cit->second.product,
|
||||
use_latex_path);
|
||||
os << outstring;
|
||||
return lyx::count(outstring.begin(), outstring.end(), '\n');
|
||||
}
|
||||
@ -213,7 +216,7 @@ string const InsetExternal::getScreenLabel(Buffer const *) const
|
||||
if (et.guiName.empty())
|
||||
return _("External");
|
||||
else
|
||||
return doSubstitution(0, et.guiName);
|
||||
return doSubstitution(0, et.guiName, false);
|
||||
}
|
||||
|
||||
|
||||
@ -230,8 +233,26 @@ void InsetExternal::executeCommand(string const & s,
|
||||
}
|
||||
|
||||
|
||||
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 ?
|
||||
latex_path(path) : os::external_path(path);
|
||||
return subst(input, placeholder, path2);
|
||||
}
|
||||
|
||||
} // namespace anon
|
||||
|
||||
|
||||
string const InsetExternal::doSubstitution(Buffer const * buffer,
|
||||
string const & s) const
|
||||
string const & s,
|
||||
bool use_latex_path) const
|
||||
{
|
||||
string result;
|
||||
string const basename = ChangeExtension(params_.filename, string());
|
||||
@ -239,12 +260,13 @@ string const InsetExternal::doSubstitution(Buffer const * buffer,
|
||||
if (buffer && !buffer->tmppath.empty() && !buffer->niceFile) {
|
||||
filepath = buffer->filePath();
|
||||
}
|
||||
result = subst(s, "$$FName", params_.filename);
|
||||
result = subst(result, "$$Basename", basename);
|
||||
result = subst_path(s, "$$FName", params_.filename, use_latex_path);
|
||||
result = subst_path(result, "$$Basename", basename, use_latex_path);
|
||||
result = subst(result, "$$Parameters", params_.parameters);
|
||||
result = subst(result, "$$FPath", filepath);
|
||||
result = subst(result, "$$Tempname", tempname_);
|
||||
result = subst(result, "$$Sysdir", lyx::package().system_support());
|
||||
result = subst_path(result, "$$FPath", filepath, use_latex_path);
|
||||
result = subst_path(result, "$$Tempname", tempname_, use_latex_path);
|
||||
result = subst_path(result, "$$Sysdir",
|
||||
lyx::package().system_support(), use_latex_path);
|
||||
|
||||
// Handle the $$Contents(filename) syntax
|
||||
if (contains(result, "$$Contents(\"")) {
|
||||
@ -287,8 +309,8 @@ void InsetExternal::updateExternal(string const & format,
|
||||
return;
|
||||
|
||||
if (!cit->second.updateResult.empty()) {
|
||||
string const resultfile = doSubstitution(buf,
|
||||
cit->second.updateResult);
|
||||
string const resultfile =
|
||||
doSubstitution(buf, cit->second.updateResult, false);
|
||||
FileInfo fi(params_.filename);
|
||||
FileInfo fi2(resultfile);
|
||||
if (fi2.exist() && fi.exist() &&
|
||||
@ -300,7 +322,8 @@ void InsetExternal::updateExternal(string const & format,
|
||||
}
|
||||
}
|
||||
|
||||
executeCommand(doSubstitution(buf, cit->second.updateCommand), buf);
|
||||
executeCommand(doSubstitution(buf, cit->second.updateCommand, false),
|
||||
buf);
|
||||
}
|
||||
|
||||
|
||||
@ -312,7 +335,7 @@ void InsetExternal::viewExternal() const
|
||||
|
||||
updateExternal();
|
||||
executeCommand(doSubstitution(view_->buffer(),
|
||||
et.viewCommand),
|
||||
et.viewCommand, false),
|
||||
view_->buffer());
|
||||
}
|
||||
|
||||
@ -325,7 +348,7 @@ void InsetExternal::editExternal() const
|
||||
|
||||
updateExternal();
|
||||
executeCommand(doSubstitution(view_->buffer(),
|
||||
et.editCommand),
|
||||
et.editCommand, false),
|
||||
view_->buffer());
|
||||
}
|
||||
|
||||
|
@ -110,7 +110,9 @@ private:
|
||||
void executeCommand(string const & s, Buffer const * buf) const;
|
||||
|
||||
/// Substitute meta-variables in this string
|
||||
string const doSubstitution(Buffer const *, string const & s) const;
|
||||
string const doSubstitution(Buffer const *,
|
||||
string const & s,
|
||||
bool use_latex_path) const;
|
||||
|
||||
/// our owning view
|
||||
BufferView * view_;
|
||||
|
@ -775,7 +775,7 @@ int InsetGraphics::latex(Buffer const *buf, ostream & os,
|
||||
buf->filePath()),
|
||||
m_buffer->filePath());
|
||||
}
|
||||
latex_str += os::external_path(fname);
|
||||
latex_str += latex_path(fname);
|
||||
}
|
||||
latex_str += '}' + after;
|
||||
|
||||
|
@ -324,7 +324,7 @@ int InsetInclude::latex(Buffer const * buffer, ostream & os,
|
||||
#endif
|
||||
writefile = AddName(m_buffer->tmppath, incfile);
|
||||
} else
|
||||
writefile = getFileName();
|
||||
writefile = getFileName();
|
||||
|
||||
writefile = ChangeExtension(writefile, ".tex");
|
||||
lyxerr[Debug::LATEX] << "incfile:" << incfile << endl;
|
||||
@ -344,21 +344,27 @@ int InsetInclude::latex(Buffer const * buffer, ostream & os,
|
||||
}
|
||||
|
||||
if (isVerbatim()) {
|
||||
incfile = latex_path(incfile);
|
||||
os << '\\' << params_.cparams.getCmdName() << '{' << incfile << '}';
|
||||
} else if (params_.flag == INPUT) {
|
||||
// \input wants file with extension (default is .tex)
|
||||
if (!IsLyXFilename(getFileName())) {
|
||||
incfile = latex_path(incfile);
|
||||
os << '\\' << params_.cparams.getCmdName() << '{' << incfile << '}';
|
||||
} else {
|
||||
incfile = ChangeExtension(incfile, ".tex");
|
||||
incfile = latex_path(incfile);
|
||||
os << '\\' << params_.cparams.getCmdName() << '{'
|
||||
<< ChangeExtension(incfile, ".tex")
|
||||
<< incfile
|
||||
<< '}';
|
||||
}
|
||||
} else {
|
||||
// \include don't want extension and demands that the
|
||||
// file really have .tex
|
||||
incfile = ChangeExtension(incfile, string());
|
||||
incfile = latex_path(incfile);
|
||||
os << '\\' << params_.cparams.getCmdName() << '{'
|
||||
<< ChangeExtension(incfile, string())
|
||||
<< incfile
|
||||
<< '}';
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -91,6 +91,15 @@ bool IsSGMLFilename(string const & filename)
|
||||
}
|
||||
|
||||
|
||||
string const latex_path(string const & original_path)
|
||||
{
|
||||
string path = subst(original_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)
|
||||
{
|
||||
@ -1307,7 +1316,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;
|
||||
@ -1328,7 +1337,7 @@ string const MakeDisplayPath(string const & path, unsigned int threshold)
|
||||
str = head + "..." + tail;
|
||||
}
|
||||
|
||||
return prefix + str;
|
||||
return os::external_path(prefix + str);
|
||||
}
|
||||
|
||||
|
||||
|
@ -136,6 +136,19 @@ bool PutEnv(string const & envstr);
|
||||
///
|
||||
bool PutEnvPath(string const & envstr);
|
||||
|
||||
/** @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.
|
||||
*/
|
||||
string const latex_path(string const & path);
|
||||
|
||||
/// Substitutes active latex characters with underscores in filename
|
||||
string const MakeLatexName(string const & file);
|
||||
|
||||
|
@ -123,22 +123,20 @@ string::size_type os::common_path(string const &p1, string const &p2)
|
||||
|
||||
string os::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> ["
|
||||
<< p << "]->>["
|
||||
<< dos_path << ']' << std::endl;
|
||||
|
||||
return dos_path;
|
||||
}
|
||||
|
||||
|
||||
string os::internal_path(string const & p)
|
||||
{
|
||||
return subst(p,"\\","/");
|
||||
return subst(p, "\\", "/");
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user