mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-09 18:31:04 +00:00
** proper implementation of pLaTeX by Tetsuya Makimura and me, fixes many remaining problems and bugs with language "japanese" (bugs 4863, 4290, 4700 and partially 4697) **
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@26200 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
0a926bebf6
commit
a2906cb877
@ -166,8 +166,13 @@
|
||||
|
||||
% (2) strip the useless parts from \mesg. This uses the fact that TeX
|
||||
% allows to define macros with parameters delimited by arbitrary text.
|
||||
\def\strip#1patterns for #2, loaded.#3\endmark{\def\langs{#2}}
|
||||
\expandafter\strip\mesg\endmark
|
||||
\def\platexname{pLaTeX2e}
|
||||
\ifx\pfmtname\platexname
|
||||
\def\langs{japanese}
|
||||
\else
|
||||
\def\strip#1patterns for #2, loaded.#3\endmark{\def\langs{#2}}
|
||||
\expandafter\strip\mesg\endmark
|
||||
\fi
|
||||
|
||||
% (3) handle the result
|
||||
\message{^^J\prefix checking for available hyphenation patterns... \langs}
|
||||
|
@ -200,6 +200,22 @@ def checkLatex(dtl_tools):
|
||||
''' Check latex, return lyx_check_config '''
|
||||
path, LATEX = checkProg('a Latex2e program', ['latex $$i', 'platex $$i', 'latex2e $$i'])
|
||||
path, PPLATEX = checkProg('a DVI postprocessing program', ['pplatex $$i'])
|
||||
#-----------------------------------------------------------------
|
||||
path, PLATEX = checkProg('pLaTeX, the Japanese LaTeX', ['platex $$i'])
|
||||
# check if PLATEX is pLaTeX2e
|
||||
writeToFile('chklatex.ltx', '''
|
||||
\\nonstopmode
|
||||
\\@@end
|
||||
''')
|
||||
# run platex on chklatex.ltx and check result
|
||||
if cmdOutput(PLATEX + ' chklatex.ltx').find('pLaTeX2e') != -1:
|
||||
# We have the Japanese pLaTeX2e
|
||||
addToRC(r'\converter platex dvi "%s" "latex"' % PLATEX)
|
||||
LATEX = PLATEX
|
||||
else:
|
||||
PLATEX = ''
|
||||
removeFiles(['chklatex.ltx', 'chklatex.log'])
|
||||
#-----------------------------------------------------------------
|
||||
# use LATEX to convert from latex to dvi if PPLATEX is not available
|
||||
if PPLATEX == '':
|
||||
PPLATEX = LATEX
|
||||
@ -267,6 +283,7 @@ def checkFormatEntries(dtl_tools):
|
||||
\Format docbook sgml DocBook B "" "%%" "document"
|
||||
\Format docbook-xml xml "Docbook (XML)" "" "" "%%" "document"
|
||||
\Format dot dot "Graphviz Dot" "" "" "%%" "vector"
|
||||
\Format platex tex "LaTeX (pLaTeX)" "" "" "%%" "document"
|
||||
\Format literate nw NoWeb N "" "%%" "document"
|
||||
\Format lilypond ly "LilyPond music" "" "" "%%" "vector"
|
||||
\Format latex tex "LaTeX (plain)" L "" "%%" "document"
|
||||
@ -324,6 +341,7 @@ def checkFormatEntries(dtl_tools):
|
||||
\Format jlyx cjklyx "CJK LyX 1.4.x (euc-jp)" "" "" "" "document"
|
||||
\Format klyx cjklyx "CJK LyX 1.4.x (euc-kr)" "" "" "" "document"
|
||||
\Format lyxpreview lyxpreview "LyX Preview" "" "" "" ""
|
||||
\Format lyxpreview-platex lyxpreview-platex "LyX Preview (pLaTeX)" "" "" "" ""
|
||||
\Format pdftex pdftex_t PDFTEX "" "" "" ""
|
||||
\Format program "" Program "" "" "" ""
|
||||
\Format pstex pstex_t PSTEX "" "" "" ""
|
||||
@ -508,6 +526,7 @@ def checkConverterEntries():
|
||||
#
|
||||
# Entries that do not need checkProg
|
||||
addToRC(r'''\converter lyxpreview ppm "python -tt $$s/scripts/lyxpreview2bitmap.py" ""
|
||||
\converter lyxpreview-platex ppm "python -tt $$s/scripts/lyxpreview-platex2bitmap.py" ""
|
||||
\converter csv lyx "python -tt $$s/scripts/csv2lyx.py $$i $$o" ""
|
||||
\converter date dateout "python -tt $$s/scripts/date.py %d-%m-%Y > $$o" ""
|
||||
\converter docbook docbook-xml "cp $$i $$o" "xml"
|
||||
|
@ -173,11 +173,11 @@ End
|
||||
|
||||
# Traditional Japanese TeX programs require neither CJK nor inputenc
|
||||
# package.
|
||||
Encoding euc-jp-plain EUC-JP-pLaTeX "Japanese (non-CJK) (EUC-JP)" EUC-JP variable none
|
||||
Encoding euc-jp-plain EUC-JP-pLaTeX "Japanese (pLaTeX, EUC-JP)" EUC-JP variable japanese
|
||||
End
|
||||
Encoding jis-plain JIS-pLaTeX "Japanese (non-CJK) (JIS)" ISO-2022-JP variable none
|
||||
Encoding jis-plain JIS-pLaTeX "Japanese (pLaTeX, JIS)" ISO-2022-JP variable japanese
|
||||
End
|
||||
Encoding shift-jis-plain SJIS-pLaTeX "Japanese (non-CJK) (SJIS)" CP932 variable none
|
||||
Encoding shift-jis-plain SJIS-pLaTeX "Japanese (pLaTeX, SJIS)" CP932 variable japanese
|
||||
End
|
||||
|
||||
# This one needs hardcoded support, since the inputenc package does not know
|
||||
|
@ -224,8 +224,11 @@ def crop_files(pnmcrop, basename):
|
||||
|
||||
|
||||
def legacy_conversion(argv):
|
||||
latex_commands = ["latex", "pplatex", "platex", "latex2e"]
|
||||
# Parse and manipulate the command line arguments.
|
||||
if len(argv) != 6:
|
||||
if len(argv) == 7:
|
||||
latex_commands = [argv[6]]
|
||||
elif len(argv) != 6:
|
||||
error(usage(argv[0]))
|
||||
|
||||
dir, latex_file = os.path.split(argv[1])
|
||||
@ -242,7 +245,7 @@ def legacy_conversion(argv):
|
||||
|
||||
# External programs used by the script.
|
||||
path = string.split(os.environ["PATH"], os.pathsep)
|
||||
latex = find_exe_or_terminate(["latex", "pplatex", "platex", "latex2e"], path)
|
||||
latex = find_exe_or_terminate(latex_commands, path)
|
||||
|
||||
# Move color information into the latex file.
|
||||
if not legacy_latex_file(latex_file, fg_color, bg_color, bg_color_gr):
|
||||
|
34
lib/scripts/lyxpreview-platex2bitmap.py
Normal file
34
lib/scripts/lyxpreview-platex2bitmap.py
Normal file
@ -0,0 +1,34 @@
|
||||
#! /usr/bin/env python
|
||||
|
||||
# This script takes a pLaTeX file and generates a collection of
|
||||
# png or ppm image files, one per previewed snippet.
|
||||
# Example usage:
|
||||
# lyxpreview-platex2bitmap.py ppm 0lyxpreview.tex 128 000000 faf0e6
|
||||
|
||||
# This script takes five arguments:
|
||||
# FORMAT: The desired output format. 'ppm'.
|
||||
# TEXFILE: the name of the .tex file to be converted.
|
||||
# DPI: a scale factor, used to ascertain the resolution of the
|
||||
# generated image which is then passed to gs.
|
||||
# FG_COLOR: the foreground color as a hexadecimal string, eg '000000'.
|
||||
# BG_COLOR: the background color as a hexadecimal string, eg 'faf0e6'.
|
||||
|
||||
import sys
|
||||
from legacy_lyxpreview2ppm import legacy_conversion
|
||||
|
||||
def usage(prog_name):
|
||||
return "Usage: %s <format> <latex file> <dpi> <fg color> <bg color>\n"\
|
||||
"\twhere the colors are hexadecimal strings, eg 'faf0e6'"\
|
||||
% prog_name
|
||||
|
||||
def main(argv):
|
||||
# Parse and manipulate the command line arguments.
|
||||
if len(argv) != 6:
|
||||
error(usage(argv[0]))
|
||||
# The arguments of legacy_conversion are the same as
|
||||
# those used in LyX 1.3.x, except for the last argument.
|
||||
vec = [ argv[0], argv[2], argv[3], argv[1], argv[4], argv[5], "platex"]
|
||||
return legacy_conversion(vec)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main(sys.argv)
|
@ -1087,6 +1087,8 @@ void Buffer::writeLaTeXSource(odocstream & os,
|
||||
// Write the preamble
|
||||
runparams.use_babel = params().writeLaTeX(os, features, d->texrow);
|
||||
|
||||
runparams.use_japanese = features.isRequired("japanese");
|
||||
|
||||
if (!output_body)
|
||||
return;
|
||||
|
||||
@ -2313,6 +2315,8 @@ string Buffer::bufferFormat() const
|
||||
return "docbook";
|
||||
if (isLiterate())
|
||||
return "literate";
|
||||
if (params().encoding().package() == Encoding::japanese)
|
||||
return "platex";
|
||||
return "latex";
|
||||
}
|
||||
|
||||
|
@ -1063,7 +1063,7 @@ bool BufferParams::writeLaTeX(odocstream & os, LaTeXFeatures & features,
|
||||
// set font encoding
|
||||
// this one is not per buffer
|
||||
// for arabic_arabi and farsi we also need to load the LAE and LFE encoding
|
||||
if (lyxrc.fontenc != "default") {
|
||||
if (lyxrc.fontenc != "default" && language->lang() != "japanese") {
|
||||
if (language->lang() == "arabic_arabi" || language->lang() == "farsi") {
|
||||
os << "\\usepackage[" << from_ascii(lyxrc.fontenc)
|
||||
<< ",LFE,LAE]{fontenc}\n";
|
||||
@ -1870,11 +1870,11 @@ void BufferParams::writeEncodingPreamble(odocstream & os,
|
||||
// If the encodings EUC-JP-plain, JIS-plain, or SJIS-plain are used, the
|
||||
// package inputenc must be omitted. Therefore set the encoding to empty.
|
||||
// see http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg129680.html
|
||||
if (doc_encoding == "EUC-JP-plain" || doc_encoding == "JIS-plain" ||
|
||||
doc_encoding == "SJIS-plain")
|
||||
encodings.clear();
|
||||
if (package == Encoding::japanese)
|
||||
features.require("japanese");
|
||||
|
||||
if (!encodings.empty() || package == Encoding::inputenc) {
|
||||
if ((!encodings.empty() || package == Encoding::inputenc)
|
||||
&& !features.isRequired("japanese")) {
|
||||
os << "\\usepackage[";
|
||||
set<string>::const_iterator it = encodings.begin();
|
||||
set<string>::const_iterator const end = encodings.end();
|
||||
@ -1899,8 +1899,12 @@ void BufferParams::writeEncodingPreamble(odocstream & os,
|
||||
} else if (inputenc != "default") {
|
||||
switch (encoding().package()) {
|
||||
case Encoding::none:
|
||||
case Encoding::japanese:
|
||||
break;
|
||||
case Encoding::inputenc:
|
||||
// do not load inputenc if japanese is used
|
||||
if (features.isRequired("japanese"))
|
||||
break;
|
||||
os << "\\usepackage[" << from_ascii(inputenc)
|
||||
<< "]{inputenc}\n";
|
||||
texrow.newline();
|
||||
|
@ -761,6 +761,8 @@ void Encodings::read(FileName const & encfile, FileName const & symbolsfile)
|
||||
package = Encoding::inputenc;
|
||||
else if (p == "CJK")
|
||||
package = Encoding::CJK;
|
||||
else if (p == "japanese")
|
||||
package = Encoding::japanese;
|
||||
else
|
||||
lex.printError("Unknown package");
|
||||
|
||||
|
@ -45,7 +45,8 @@ public:
|
||||
enum Package {
|
||||
none,
|
||||
inputenc,
|
||||
CJK
|
||||
CJK,
|
||||
japanese
|
||||
};
|
||||
///
|
||||
Encoding() {}
|
||||
|
@ -373,12 +373,13 @@ void LaTeXFeatures::useLanguage(Language const * lang)
|
||||
UsedLanguages_.insert(lang);
|
||||
if (lang->lang() == "vietnamese")
|
||||
require("vietnamese");
|
||||
else if (lang->lang() == "japanese")
|
||||
require("japanese");
|
||||
// CJK languages do not have a babel name.
|
||||
// They use the CJK package
|
||||
if (lang->encoding()->package() == Encoding::CJK)
|
||||
require("CJK");
|
||||
// japanese package is special
|
||||
if (lang->encoding()->package() == Encoding::japanese)
|
||||
require("japanese");
|
||||
}
|
||||
|
||||
|
||||
@ -420,7 +421,8 @@ set<string> LaTeXFeatures::getEncodingSet(string const & doc_encoding) const
|
||||
LanguageList::const_iterator end = UsedLanguages_.end();
|
||||
for (; it != end; ++it)
|
||||
if ((*it)->encoding()->latexName() != doc_encoding &&
|
||||
(*it)->encoding()->package() == Encoding::inputenc)
|
||||
((*it)->encoding()->package() == Encoding::inputenc
|
||||
|| (*it)->encoding()->package() == Encoding::japanese))
|
||||
encodings.insert((*it)->encoding()->latexName());
|
||||
return encodings;
|
||||
}
|
||||
|
@ -12,6 +12,7 @@
|
||||
|
||||
#include "OutputParams.h"
|
||||
#include "Exporter.h"
|
||||
#include "Encoding.h"
|
||||
|
||||
|
||||
namespace lyx {
|
||||
@ -20,13 +21,18 @@ namespace lyx {
|
||||
OutputParams::OutputParams(Encoding const * enc)
|
||||
: flavor(LATEX), nice(false), moving_arg(false),
|
||||
local_font(0), encoding(enc), free_spacing(false), use_babel(false),
|
||||
linelen(0), depth(0),
|
||||
use_japanese(false), linelen(0), depth(0),
|
||||
exportdata(new ExportData),
|
||||
inComment(false),
|
||||
inDeletedInset(0), changeOfDeletedInset(Change::UNCHANGED),
|
||||
par_begin(0), par_end(0),
|
||||
dryrun(false), verbatim(false)
|
||||
{}
|
||||
{
|
||||
// Note: in PreviewLoader::Impl::dumpPreamble
|
||||
// OutputParams runparams(0);
|
||||
if (enc && enc->package() == Encoding::japanese)
|
||||
use_japanese = true;
|
||||
}
|
||||
|
||||
|
||||
OutputParams::~OutputParams()
|
||||
|
@ -98,6 +98,10 @@ public:
|
||||
*/
|
||||
bool use_babel;
|
||||
|
||||
/** Are we using japanese (pLaTeX)?
|
||||
*/
|
||||
bool use_japanese;
|
||||
|
||||
/** Line length to use with plaintext export.
|
||||
*/
|
||||
size_type linelen;
|
||||
|
@ -67,10 +67,8 @@ string const unique_filename(string const & bufferpath)
|
||||
}
|
||||
|
||||
|
||||
lyx::Converter const * setConverter()
|
||||
lyx::Converter const * setConverter(string const from)
|
||||
{
|
||||
string const from = "lyxpreview";
|
||||
|
||||
typedef vector<string> FmtList;
|
||||
typedef lyx::graphics::Cache GCache;
|
||||
FmtList const & loadableFormats = GCache::get().loadableFormats();
|
||||
@ -397,8 +395,12 @@ PreviewLoader::Impl::Impl(PreviewLoader & p, Buffer const & b)
|
||||
LYXERR(Debug::GRAPHICS, "The font scaling factor is "
|
||||
<< font_scaling_factor_);
|
||||
|
||||
if (!pconverter_)
|
||||
pconverter_ = setConverter();
|
||||
if (!pconverter_){
|
||||
if (b.params().encoding().package() == Encoding::japanese)
|
||||
pconverter_ = setConverter("lyxpreview-platex");
|
||||
else
|
||||
pconverter_ = setConverter("lyxpreview");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -901,6 +901,7 @@ pair<bool, int> switchEncoding(odocstream & os, BufferParams const & bparams,
|
||||
docstring const inputenc_arg(from_ascii(newEnc.latexName()));
|
||||
switch (newEnc.package()) {
|
||||
case Encoding::none:
|
||||
case Encoding::japanese:
|
||||
// shouldn't ever reach here, see above
|
||||
return make_pair(true, 0);
|
||||
case Encoding::inputenc: {
|
||||
@ -924,6 +925,9 @@ pair<bool, int> switchEncoding(odocstream & os, BufferParams const & bparams,
|
||||
count += 7;
|
||||
open_encoding_ = inputenc;
|
||||
}
|
||||
// with the japanese option, inputenc is omitted.
|
||||
if (runparams.use_japanese)
|
||||
return make_pair(true, count);
|
||||
os << "\\inputencoding{" << inputenc_arg << '}';
|
||||
return make_pair(true, count + 16);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user