From 9ebd4405cf162a528aaa9d7357a574a2f22c4f5d Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Fri, 22 Oct 2010 07:51:39 +0000 Subject: [PATCH] Make sweave process files with the correct encoding (#6625). The required the introduction of the new converter token $$e, that holds the iconv name of the latex file encoding. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@35772 a592a061-630c-0410-9148-cb99ea01b6c8 --- lib/configure.py | 2 +- lib/doc/Customization.lyx | 27 +++++++++++++++++++++++++-- lib/scripts/lyxsweave.R | 13 +++++++++---- src/Converter.cpp | 12 +++++++----- 4 files changed, 42 insertions(+), 12 deletions(-) diff --git a/lib/configure.py b/lib/configure.py index 1ea4c680f4..48cdb7de7e 100644 --- a/lib/configure.py +++ b/lib/configure.py @@ -612,7 +612,7 @@ def checkConverterEntries(): rc_entry = [r'''\converter literate latex "%%" "" \converter literate pdflatex "%%" ""''']) # - checkProg('a Sweave -> LaTeX converter', ['Rscript --vanilla $$s/scripts/lyxsweave.R $$i'], + checkProg('a Sweave -> LaTeX converter', ['Rscript --vanilla $$s/scripts/lyxsweave.R $$i $$e'], rc_entry = [r'''\converter sweave latex "%%" "" \converter sweave pdflatex "%%" ""''']) # diff --git a/lib/doc/Customization.lyx b/lib/doc/Customization.lyx index 30426b4fdb..2f76dadb26 100644 --- a/lib/doc/Customization.lyx +++ b/lib/doc/Customization.lyx @@ -133,10 +133,11 @@ End \papercolumns 1 \papersides 2 \paperpagestyle headings -\tracking_changes false +\tracking_changes true \output_changes false \html_math_output 0 \html_be_strict true +\author 1 "Jean-Marc Lasgouttes" \end_header \begin_body @@ -2140,7 +2141,29 @@ $$r \end_inset The path to the original input file (this is different from $$p when a - chain of converters is called). + chain of converters is called) +\change_deleted 1 1287732759 +. +\change_inserted 1 1287732721 + +\end_layout + +\begin_layout Labeling +\labelwidthstring 00.00.0000 + +\change_inserted 1 1287732753 +\begin_inset Flex Code +status collapsed + +\begin_layout Plain Layout + +\change_inserted 1 1287732729 +$$e +\end_layout + +\end_inset + + The iconv name for the encoding of the document. \end_layout \begin_layout Standard diff --git a/lib/scripts/lyxsweave.R b/lib/scripts/lyxsweave.R index 8ab0ea9951..a8ab184984 100644 --- a/lib/scripts/lyxsweave.R +++ b/lib/scripts/lyxsweave.R @@ -1,10 +1,15 @@ # Wrapper around Sweave that sets up some things for LyX # argument 1 is the file name +# argument 2 is the iconv name for the encoding of the file -args <- commandArgs(trailingOnly=T) +ls.args <- commandArgs(trailingOnly=T) # check whether Sweave.sty is seen by LaTeX -sweavesty <- system("kpsewhich Sweave.sty", intern=T, ignore.stderr=T) -sp <- (length(sweavesty) == 0) +ls.sweavesty <- system("kpsewhich Sweave.sty", intern=T, ignore.stderr=T) +ls.sp <- (length(ls.sweavesty) == 0) -Sweave(args[1], stylepath=sp) +# set default encoding to the one of the file +options(encoding=ls.args[2]) + +#run sweave +Sweave(ls.args[1], stylepath=ls.sp) diff --git a/src/Converter.cpp b/src/Converter.cpp index 14f4522968..4128129fc7 100644 --- a/src/Converter.cpp +++ b/src/Converter.cpp @@ -12,10 +12,11 @@ #include "Converter.h" -#include "ConverterCache.h" #include "Buffer.h" #include "buffer_funcs.h" #include "BufferParams.h" +#include "ConverterCache.h" +#include "Encoding.h" #include "ErrorList.h" #include "Format.h" #include "Language.h" @@ -49,7 +50,7 @@ string const token_base("$$b"); string const token_to("$$o"); string const token_path("$$p"); string const token_orig_path("$$r"); - +string const token_encoding("$$e"); string const add_options(string const & command, string const & options) @@ -325,7 +326,7 @@ bool Converters::convert(Buffer const * buffer, // used anyway. OutputParams runparams(buffer ? &buffer->params().encoding() : 0); runparams.flavor = getFlavor(edgepath); - + if (buffer) { runparams.use_japanese = buffer->bufferFormat() == "platex"; runparams.use_indices = buffer->params().use_indices; @@ -397,9 +398,9 @@ bool Converters::convert(Buffer const * buffer, } // FIXME UNICODE - string const infile2 = + string const infile2 = to_utf8(makeRelPath(from_utf8(infile.absFileName()), from_utf8(path))); - string const outfile2 = + string const outfile2 = to_utf8(makeRelPath(from_utf8(outfile.absFileName()), from_utf8(path))); string command = conv.command; @@ -408,6 +409,7 @@ bool Converters::convert(Buffer const * buffer, command = subst(command, token_to, quoteName(outfile2)); command = subst(command, token_path, quoteName(infile.onlyPath().absFileName())); command = subst(command, token_orig_path, quoteName(orig_from.onlyPath().absFileName())); + command = subst(command, token_encoding, buffer ? buffer->params().encoding().iconvName() : string()); command = libScriptSearch(command); if (!conv.parselog.empty()) -- 2.39.2