Fix tex2lyx bug #8466: special file names.

Special characters as created by latex_path() where not converted corectly
from LaTeX macros by tex2lyx. Now this is done, even for file names containing
double quotes which are not used for quoting spaces. These file names are not
legal on windows, and will causes probelms in DVI files, but if they occur
tex2lyx does not produce invalid .lyx files.
This commit is contained in:
Georg Baum 2012-12-29 13:16:22 +01:00
parent d3b94fed30
commit c51449cac6
8 changed files with 243 additions and 12 deletions

View File

@ -24,6 +24,8 @@ TEST_FILES = \
test/box-color-size-space-align.tex \
test/CJK.tex \
test/DummyDocument.tex \
test/Dummy~Document.tex \
test/Dummy\ Document.tex \
test/foo.eps \
test/foo.png \
test/test-insets.tex \

View File

@ -0,0 +1,89 @@
#LyX file created by tex2lyx 2.1.0dev
\lyxformat 457
\begin_document
\begin_header
\textclass article
\use_default_options false
\maintain_unincluded_children false
\language english
\language_package none
\inputencoding latin9
\fontencoding T1
\font_roman default
\font_sans default
\font_typewriter default
\font_math auto
\font_default_family default
\use_non_tex_fonts false
\font_sc false
\font_osf false
\font_sf_scale 100
\font_tt_scale 100
\graphics default
\default_output_format default
\output_sync 0
\bibtex_command default
\index_command default
\paperfontsize 12
\spacing onehalf
\use_hyperref true
\pdf_bookmarks 1
\pdf_bookmarksnumbered 0
\pdf_bookmarksopen 0
\pdf_bookmarksopenlevel 1
\pdf_breaklinks 0
\pdf_pdfborder 0
\pdf_colorlinks 0
\pdf_backref section
\pdf_pdfusetitle 1
\papersize a4paper
\use_geometry false
\use_package amsmath 2
\use_package amssymb 2
\use_package esint 1
\use_package mathdots 0
\use_package mathtools 0
\use_package mhchem 0
\use_package stackrel 0
\use_package stmaryrd 0
\use_package undertilde 0
\cite_engine natbib
\cite_engine_type numerical
\biblio_style plainnat
\use_bibtopic false
\use_indices true
\paperorientation portrait
\suppress_date false
\justification true
\use_refstyle 0
\index Index
\shortcut idx
\color #008000
\end_index
\secnumdepth 3
\tocdepth 3
\paragraph_separation indent
\paragraph_indentation 3mm
\quotes_language english
\papercolumns 1
\papersides 1
\paperpagestyle default
\tracking_changes false
\output_changes false
\html_math_output 0
\html_css_as_file 0
\html_be_strict false
\end_header
\begin_body
\begin_layout Subsection
Space Test
\end_layout
\begin_layout Standard
The file name contains a space.
\end_layout
\end_body
\end_document

View File

@ -0,0 +1,2 @@
\subsection{Space Test}
The file name contains a space.

View File

@ -0,0 +1,89 @@
#LyX file created by tex2lyx 2.1.0dev
\lyxformat 457
\begin_document
\begin_header
\textclass article
\use_default_options false
\maintain_unincluded_children false
\language english
\language_package none
\inputencoding latin9
\fontencoding T1
\font_roman default
\font_sans default
\font_typewriter default
\font_math auto
\font_default_family default
\use_non_tex_fonts false
\font_sc false
\font_osf false
\font_sf_scale 100
\font_tt_scale 100
\graphics default
\default_output_format default
\output_sync 0
\bibtex_command default
\index_command default
\paperfontsize 12
\spacing onehalf
\use_hyperref true
\pdf_bookmarks 1
\pdf_bookmarksnumbered 0
\pdf_bookmarksopen 0
\pdf_bookmarksopenlevel 1
\pdf_breaklinks 0
\pdf_pdfborder 0
\pdf_colorlinks 0
\pdf_backref section
\pdf_pdfusetitle 1
\papersize a4paper
\use_geometry false
\use_package amsmath 2
\use_package amssymb 2
\use_package esint 1
\use_package mathdots 0
\use_package mathtools 0
\use_package mhchem 0
\use_package stackrel 0
\use_package stmaryrd 0
\use_package undertilde 0
\cite_engine natbib
\cite_engine_type numerical
\biblio_style plainnat
\use_bibtopic false
\use_indices true
\paperorientation portrait
\suppress_date false
\justification true
\use_refstyle 0
\index Index
\shortcut idx
\color #008000
\end_index
\secnumdepth 3
\tocdepth 3
\paragraph_separation indent
\paragraph_indentation 3mm
\quotes_language english
\papercolumns 1
\papersides 1
\paperpagestyle default
\tracking_changes false
\output_changes false
\html_math_output 0
\html_css_as_file 0
\html_be_strict false
\end_header
\begin_body
\begin_layout Subsection
Tilde Test
\end_layout
\begin_layout Standard
The file name contains a tilde.
\end_layout
\end_body
\end_document

View File

@ -0,0 +1,2 @@
\subsection{Tilde Test}
The file name contains a tilde.

View File

@ -697,25 +697,43 @@ filename "DummyDocument.lyx"
\end_inset
, or with the include variant
, or with the include variant (tests quoting as well):
\begin_inset CommandInset include
LatexCommand include
preview false
filename "DummyDocument.lyx"
filename "Dummy Document.lyx"
\end_inset
\begin_inset ERT
status collapsed
\begin_inset CommandInset include
LatexCommand include
preview false
filename "Dummy Document.lyx"
\begin_layout Standard
% unfortunately, including the doc twice generates a multiply defined label
\end_layout
\end_inset
\begin_layout Standard
\end_layout
\begin_inset CommandInset include
LatexCommand include
preview false
filename "Dummy~Document.lyx"
\end_inset
\begin_inset CommandInset include
LatexCommand include
preview false
filename "Dummy~Document.lyx"
\end_inset
File names containg double quotes are not legal on windows, so no test file is provided. Nevertheless, they are legal on unix, so we test at least the paring. Since the file does not exist, the variant without extension would not work (tex2lyx can't deduce the correct extension of nonexisting files).
\begin_inset CommandInset include
LatexCommand include
preview false
filename "Dummy\"Document.tex"
\end_inset

View File

@ -134,7 +134,16 @@ M., \& Rasio, F.~A. 2004, ApJ, 604, 632\end{thebibliography}
\section{Input files\index{Input files}}
We can input files too, like this \input{DummyDocument}, or with the include
variant \include{DummyDocument} % unfortunately, including the doc twice generates a multiply defined label
variant (tests quoting as well):
\include{\string"Dummy\space Document\string"}
\include{\string"Dummy Document\string".tex}
\include{\string"Dummy\string~Document\string"}
\include{\string"Dummy\string~Document\string".tex}
File names containg double quotes are not legal on windows, so no test file
is provided. Nevertheless, they are legal on unix, so we test at least the
paring. Since the file does not exist, the variant without extension would
not work (tex2lyx can't deduce the correct extension of nonexisting files).
\include{\string"Dummy\string"Document\string".tex}
We can also import chess diagrams:

View File

@ -1839,7 +1839,7 @@ void get_cite_arguments(Parser & p, bool natbibOrder,
/// can understand
string const normalize_filename(string const & name)
{
Parser p(trim(name, "\""));
Parser p(name);
ostringstream os;
while (p.good()) {
Token const & t = p.get_token();
@ -1853,10 +1853,29 @@ string const normalize_filename(string const & name)
} else if (t.cs() == "space") {
os << ' ';
p.skip_spaces();
} else if (t.cs() == "string") {
// Convert \string" to " and \string~ to ~
Token const & n = p.next_token();
if (n.asInput() != "\"" && n.asInput() != "~")
os << t.asInput();
} else
os << t.asInput();
}
return os.str();
// Strip quotes. This is a bit complicated (see latex_path()).
string full = os.str();
if (!full.empty() && full[0] == '"') {
string base = removeExtension(full);
string ext = getExtension(full);
if (!base.empty() && base[base.length()-1] == '"')
// "a b"
// "a b".tex
return addExtension(trim(base, "\""), ext);
if (full[full.length()-1] == '"')
// "a b.c"
// "a b.c".tex
return trim(full, "\"");
}
return full;
}
@ -3925,6 +3944,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
registerExternalTemplatePackages("XFig");
} else {
begin_command_inset(os, "include", name);
outname = subst(outname, "\"", "\\\"");
os << "preview false\n"
"filename \"" << outname << "\"\n";
if (t.cs() == "verbatiminput")