Jürgen Spitzmüller <[EMAIL PROTECTED]> writes: > First, we need to use our LaTeXFeatures > mechanism to tell LyX that we use the > japanese package. I've done that > in the following patch, which is not applied > yet (since it still needs testing): > http://bugzilla.lyx.org/attachment.cgi?id=2678&action=view
Hi, Jürgen. Thank you very much for your patch. Based on your patch #2678, I implemented automatic configuration, as attached below. As you suggested, I added jlatex format and a converter from jlatex to dvi in lib/configure.py. In addition, I rewrote the script to detect Japanese pLaTeX by itself without any option. > Using this, you could then specify > e.g. in Buffer::doExport and probably other > places, where this is needed: > > } else { > backend_format = format; > // FIXME: Don't hardcode format names here, but use a flag > if (backend_format == "pdflatex") > runparams.flavor = OutputParams::PDFLATEX; > + else if (runparams.use_japanese) > + runparams.flavor = OutputParams::PLATEX; > } If you are going to pass runparams to theConverters().convert as an additional argument, your codes above will works fine. It is noted that the converter do not have any way to detect the flavor: in the function Buffer::doExport bool const success = theConverters().convert(this, FileName(filename), tmp_result_file, FileName(absFileName()), backend_format, format, error_list); Instead, I have changed the function Buffer::bufferFormat() using the file format 'jlatex' that you introduced: string Buffer::bufferFormat() const { if (isDocBook()) return "docbook"; if (isLiterate()) return "literate"; // if( isPLATEX() ) if ( params().encoding().package() == Encoding::japanese ) return "jlatex"; return "latex"; } Although OutputParams::flavor is used to adjust LaTeX source codes to fit converters, OupputParam::PLATEX uses just the codes as OutputParam::LATEX does. The exceptions are babel, inputenc and CJK, which are processed by language, encoding and package not by flavor. > I guess you will need to go further through the code. > Flavor is spreaded all > over the place, but I'm sure it can be implemented this way. > > > Therefore, there should be a way for platex users to specify flavor > > manually, say, in a GUI panel. > > I think we can do better. In your framework, 'platex' is selected by Document->Settings->Language->->{Language,Encoding} in the Document Settings panel. Thank you. Tetsuya Makimura Note that \\\ indicates continued lines. ########################################################################### Index: src/OutputParams.h =================================================================== --- src/OutputParams.h (revision 25709) +++ src/OutputParams.h (working copy) @@ -98,6 +98,10 @@ */ bool use_babel; + /** Are we using japanese (pLaTeX)? + */ + bool use_japanese; + /** Line length to use with plaintext export. */ size_type linelen; Index: src/LaTeXFeatures.cpp =================================================================== --- src/LaTeXFeatures.cpp (revision 25709) +++ src/LaTeXFeatures.cpp (working copy) @@ -379,6 +379,9 @@ // 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 +423,8 @@ 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; } @@ -582,7 +586,7 @@ // setspace.sty if (mustProvide("setspace") && !tclass.provides("SetSpace")) - packages << "\\usepackage{setspace}\n"; + packages << "\\usepackage{setspace}\n"; // amssymb.sty if (mustProvide("amssymb") Index: src/output_latex.cpp =================================================================== --- src/output_latex.cpp (revision 25709) +++ src/output_latex.cpp (working copy) @@ -900,6 +900,7 @@ 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: { @@ -923,6 +924,9 @@ count += 7; open_encoding_ = inputenc; } + // with the japanese option, inputenc is ommitted. + if (runparams.use_japanese) + return make_pair(true, count); os << "\\inputencoding{" << inputenc_arg << '}'; return make_pair(true, count + 16); } Index: src/OutputParams.cpp =================================================================== --- src/OutputParams.cpp (revision 25709) +++ src/OutputParams.cpp (working copy) @@ -12,6 +12,7 @@ #include "OutputParams.h" #include "Exporter.h" +#include "Encoding.h" namespace lyx { @@ -20,13 +21,16 @@ 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) -{} +{ + if (enc->package() == Encoding::japanese) + use_japanese = true; +} OutputParams::~OutputParams() Index: src/Encoding.cpp =================================================================== --- src/Encoding.cpp (revision 25709) +++ src/Encoding.cpp (working copy) @@ -753,6 +753,8 @@ package = Encoding::inputenc; else if (p == "CJK") package = Encoding::CJK; + else if (p == "japanese") + package = Encoding::japanese; else lex.printError("Unknown package"); Index: src/Buffer.cpp =================================================================== --- src/Buffer.cpp (revision 25709) +++ src/Buffer.cpp (working copy) @@ -1079,6 +1079,8 @@ // Write the preamble runparams.use_babel = params().writeLaTeX(os, features, d->texrow); + runparams.use_japanese = features.isRequired("japanese"); + if (!output_body) return; @@ -2299,6 +2301,9 @@ return "docbook"; if (isLiterate()) return "literate"; + // if( isPLATEX() ) + if ( params().encoding().package() == Encoding::japanese ) + return "jlatex"; return "latex"; } Index: src/BufferParams.cpp =================================================================== --- src/BufferParams.cpp (revision 25709) +++ src/BufferParams.cpp (working copy) @@ -1055,6 +1055,8 @@ os << "\\usepackage[" << from_ascii(lyxrc.fontenc) << ",LFE,LAE]{fontenc}\n"; texrow.newline(); + }else if (language->lang() == "japanese"){ + ; // do nothing. } else { os << "\\usepackage[" << from_ascii(lyxrc.fontenc) << "]{fontenc}\n"; @@ -1792,11 +1794,11 @@ // 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(); @@ -1821,8 +1823,12 @@ } 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(); Index: src/Encoding.h =================================================================== --- src/Encoding.h (revision 25709) +++ src/Encoding.h (working copy) @@ -45,7 +45,8 @@ enum Package { none, inputenc, - CJK + CJK, + japanese }; /// Encoding() {} Index: lib/scripts/lyxpreview2bitmap.py =================================================================== --- lib/scripts/lyxpreview2bitmap.py (revision 25709) +++ lib/scripts/lyxpreview2bitmap.py (working copy) @@ -154,7 +154,16 @@ def main(argv): # Parse and manipulate the command line arguments. - if len(argv) != 6: + + if len(argv) == 6: + latex_command = "" + elif len(argv) == 7: + if argv[1][0:16] == "--latex-command=": + latex_command = argv[1][16:] + argv[1:2] = [] + else: + error(usage(argv[0])) + else: error(usage(argv[0])) output_format = string.lower(argv[1]) @@ -171,8 +180,12 @@ # External programs used by the script. path = string.split(os.environ["PATH"], os.pathsep) - latex = find_exe_or_terminate(\\\ ["latex", "pplatex", "platex", "latex2e"], path) + if len(latex_command) > 0: + latex = find_exe_or_terminate([latex_command], path) + else: + latex = find_exe_or_terminate(\\\ ["latex", "pplatex", "platex", "latex2e"], path) + # This can go once dvipng becomes widespread. dvipng = find_exe(["dvipng"], path) if dvipng == None: Index: lib/chkconfig.ltx =================================================================== --- lib/chkconfig.ltx (revision 25709) +++ lib/chkconfig.ltx (working copy) @@ -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} Index: lib/languages =================================================================== --- lib/languages (revision 25709) +++ lib/languages (working copy) @@ -52,7 +52,7 @@ interlingua interlingua "Interlingua" false iso8859-15 ia "" irish irish "Irish" false iso8859-15 ga_IE "" italian italian "Italian" false iso8859-15 it_IT "" -japanese japanese "Japanese" false jis-plain ja_JP "" +japanese japanese "Japanese" false jis-platex ja_JP "" japanese-cjk "" "Japanese (CJK)" false euc-jp ja_JP "" kazakh kazakh "Kazakh" false pt154 kk_KZ "" # there is no country code for Korean because ko_KR is the same as ko_KI Index: lib/configure.py =================================================================== --- lib/configure.py (revision 25709) +++ lib/configure.py (working copy) @@ -200,6 +200,22 @@ ''' 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 jlatex 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 @@ \Format docbook sgml DocBook B "" "%%" "document" \Format docbook-xml xml "Docbook (XML)" "" "" "%%" "document" \Format dot dot "Graphviz Dot" "" "" "%%" "vector" +\Format jlatex tex "LaTeX (pLaTeX)" "" "" "%%" "document" \Format literate nw NoWeb N "" "%%" "document" \Format lilypond ly "LilyPond music" "" "" "%%" "vector" \Format latex tex "LaTeX (plain)" L "" "%%" "document" Index: lib/encodings =================================================================== --- lib/encodings (revision 25709) +++ lib/encodings (working copy) @@ -173,11 +173,11 @@ # 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-platex 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-platex 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-platex SJIS-pLaTeX \\\ "Japanese (pLaTeX, SJIS)" CP932 variable japanese End # This one needs hardcoded support, since the inputenc package does not know ###########################################################################