* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
- * \author André Pönitz
+ * \author André Pönitz
* \author Jean-Marc Lasgouttes
*
* Full author contact details are available in file CREDITS.
#include <config.h>
#include "tex2lyx.h"
+
#include "Context.h"
#include "FloatList.h"
-#include "lengthcommon.h"
+#include "Layout.h"
+#include "Length.h"
+
#include "support/lstrings.h"
#include "support/convert.h"
#include "support/filetools.h"
-#include <boost/filesystem/operations.hpp>
#include <boost/tuple/tuple.hpp>
#include <iostream>
#include <sstream>
#include <vector>
+using std::cerr;
+using std::endl;
+
+using std::map;
+using std::ostream;
+using std::ostringstream;
+using std::istringstream;
+using std::string;
+using std::vector;
namespace lyx {
using support::contains;
using support::subst;
-using std::cerr;
-using std::endl;
-
-using std::map;
-using std::ostream;
-using std::ostringstream;
-using std::istringstream;
-using std::string;
-using std::vector;
-
-namespace fs = boost::filesystem;
-
void parse_text_in_inset(Parser & p, ostream & os, unsigned flags, bool outer,
Context const & context)
}
-char const * const known_latex_commands[] = { "ref", "cite", "label", "index",
-"printindex", "pageref", "url", "vref", "vpageref", "prettyref", "eqref", 0 };
+char const * const known_latex_commands[] = { "ref", "cite", "label", "href",
+ "index", "printindex", "pageref", "url", "vref", "vpageref", "prettyref",
+ "eqref", 0 };
/*!
* natbib commands.
// expects utf8)
for (char const * const * what = extensions; *what; ++what) {
string const trial = addExtension(name, *what);
- if (fs::exists(makeAbsPath(trial, path).toFilesystemEncoding()))
+ if (makeAbsPath(trial, path).exists())
return trial;
}
return string();
}
-class isLayout : public std::unary_function<LyXLayout_ptr, bool> {
+class isLayout : public std::unary_function<LayoutPtr, bool> {
public:
isLayout(string const name) : name_(name) {}
- bool operator()(LyXLayout_ptr const & ptr) const {
+ bool operator()(LayoutPtr const & ptr) const {
return ptr->latexname() == name_;
}
private:
};
-LyXLayout_ptr findLayout(LyXTextClass const & textclass,
+LayoutPtr findLayout(TextClass const & textclass,
string const & name)
{
- LyXTextClass::const_iterator beg = textclass.begin();
- LyXTextClass::const_iterator end = textclass.end();
+ TextClass::const_iterator beg = textclass.begin();
+ TextClass::const_iterator end = textclass.end();
- LyXTextClass::const_iterator
+ TextClass::const_iterator
it = std::find_if(beg, end, isLayout(name));
- return (it == end) ? LyXLayout_ptr() : *it;
+ return (it == end) ? LayoutPtr() : *it;
}
void output_command_layout(ostream & os, Parser & p, bool outer,
Context & parent_context,
- LyXLayout_ptr newlayout)
+ LayoutPtr newlayout)
{
parent_context.check_end_layout(os);
Context context(true, parent_context.textclass, newlayout,
{
string position;
string inner_pos;
- string height_value = "0";
- string height_unit = "pt";
- string height_special = "none";
+ // We need to set the height to the LaTeX default of 1\\totalheight
+ // for the case when no height argument is given
+ string height_value = "1";
+ string height_unit = "in";
+ string height_special = "totalheight";
string latex_height;
if (p.next_token().asInput() == "[") {
position = p.getArg('[', ']');
void parse_environment(Parser & p, ostream & os, bool outer,
Context & parent_context)
{
- LyXLayout_ptr newlayout;
+ LayoutPtr newlayout;
string const name = p.getArg('{', '}');
const bool is_starred = suffixIs(name, '*');
string const unstarred_name = rtrim(name, "*");
// FIXME UNICODE encoding of name may be wrong (makeAbsPath expects
// utf8)
name = to_utf8(makeRelPath(from_utf8(makeAbsPath(name, getMasterFilePath()).absFilename()),
- from_utf8(getParentFilePath())));
+ from_utf8(getParentFilePath())));
}
}
if (!scrap || !context.new_layout_allowed ||
- !context.textclass.hasLayout("Scrap")) {
+ !context.textclass.hasLayout(from_ascii("Scrap"))) {
cerr << "Warning: Could not interpret '" << name
<< "'. Ignoring it." << endl;
return;
// noweb code chunks are implemented with a layout style in LyX they
// always must be in an own paragraph.
context.new_paragraph(os);
- Context newcontext(true, context.textclass, context.textclass["Scrap"]);
+ Context newcontext(true, context.textclass,
+ context.textclass[from_ascii("Scrap")]);
newcontext.check_layout(os);
os << name;
while (p.good()) {
void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
Context & context)
{
- LyXLayout_ptr newlayout;
+ LayoutPtr newlayout;
// Store the latest bibliographystyle (needed for bibtex inset)
string bibliographystyle;
bool const use_natbib = used_packages.find("natbib") != used_packages.end();
check_space(p, os, context);
else if (t.character() == '[' && noweb_mode &&
- p.next_token().character() == '[') {
+ p.next_token().character() == '[') {
// These can contain underscores
p.putback();
string const s = p.getFullOpt() + ']';
// special handling of font attribute changes
Token const prev = p.prev_token();
Token const next = p.next_token();
- Font const oldFont = context.font;
+ TeXFont const oldFont = context.font;
if (next.character() == '[' ||
next.character() == ']' ||
next.character() == '*') {
context.check_layout(os);
eat_whitespace(p, os, context, false);
string name = p.get_token().cs();
- while (p.next_token().cat() != catBegin)
- name += p.get_token().asString();
- handle_ert(os, "\\def\\" + name + '{' + p.verbatim_item() + '}', context);
+ eat_whitespace(p, os, context, false);
+
+ // parameter text
+ bool simple = true;
+ string paramtext;
+ int arity = 0;
+ while (p.next_token().cat() != catBegin) {
+ if (p.next_token().cat() == catParameter) {
+ // # found
+ p.get_token();
+ paramtext += "#";
+
+ // followed by number?
+ if (p.next_token().cat() == catOther) {
+ char c = p.getChar();
+ paramtext += c;
+ // number = current arity + 1?
+ if (c == arity + '0' + 1)
+ ++arity;
+ else
+ simple = false;
+ } else
+ paramtext += p.get_token().asString();
+ } else {
+ paramtext += p.get_token().asString();
+ simple = false;
+ }
+ }
+
+ // only output simple (i.e. compatible) macro as FormulaMacros
+ string ert = "\\def\\" + name + ' ' + paramtext + '{' + p.verbatim_item() + '}';
+ if (simple) {
+ context.check_layout(os);
+ begin_inset(os, "FormulaMacro");
+ os << "\n" << ert;
+ end_inset(os);
+ } else
+ handle_ert(os, ert, context);
}
else if (t.cs() == "noindent") {
p.skip_spaces();
}
+ // Special handling for \caption
+ // FIXME: remove this when InsetCaption is supported.
+ else if (context.new_layout_allowed &&
+ t.cs() == captionlayout->latexname()) {
+ output_command_layout(os, p, outer, context,
+ captionlayout);
+ p.skip_spaces();
+ }
+
else if (t.cs() == "includegraphics") {
bool const clip = p.next_token().asInput() == "*";
if (clip)
// therefore path is only used for testing
// FIXME UNICODE encoding of name and path may be
// wrong (makeAbsPath expects utf8)
- if (!fs::exists(makeAbsPath(name, path).toFilesystemEncoding())) {
+ if (!makeAbsPath(name, path).exists()) {
// The file extension is probably missing.
// Now try to find it out.
string const dvips_name =
// FIXME UNICODE encoding of name and path may be
// wrong (makeAbsPath expects utf8)
- if (fs::exists(makeAbsPath(name, path).toFilesystemEncoding()))
+ if (makeAbsPath(name, path).exists())
fix_relative_filename(name);
else
cerr << "Warning: Could not find graphics file '"
p.skip_spaces();
context.check_layout(os);
string const s = p.verbatim_item();
- if (s == "±" || s == "³" || s == "²" || s == "µ")
+ if (s == "\xb1" || s == "\xb3" || s == "\xb2" || s == "\xb5")
os << s;
else
handle_ert(os, "\\ensuremath{" + s + "}",
else if (t.cs() == "textnormal" || t.cs() == "normalfont") {
context.check_layout(os);
- Font oldFont = context.font;
+ TeXFont oldFont = context.font;
context.font.init();
context.font.size = oldFont.size;
os << "\n\\family " << context.font.family << "\n";
context.new_layout_allowed) {
char const * const * where = is_known(t.cs(), known_sizes);
context.check_layout(os);
- Font const oldFont = context.font;
+ TeXFont const oldFont = context.font;
context.font.size = known_coded_sizes[where - known_sizes];
output_font_change(os, oldFont, context.font);
eat_whitespace(p, os, context, false);
char const * const * where =
is_known(t.cs(), known_font_families);
context.check_layout(os);
- Font const oldFont = context.font;
+ TeXFont const oldFont = context.font;
context.font.family =
known_coded_font_families[where - known_font_families];
output_font_change(os, oldFont, context.font);
char const * const * where =
is_known(t.cs(), known_font_series);
context.check_layout(os);
- Font const oldFont = context.font;
+ TeXFont const oldFont = context.font;
context.font.series =
known_coded_font_series[where - known_font_series];
output_font_change(os, oldFont, context.font);
char const * const * where =
is_known(t.cs(), known_font_shapes);
context.check_layout(os);
- Font const oldFont = context.font;
+ TeXFont const oldFont = context.font;
context.font.shape =
known_coded_font_shapes[where - known_font_shapes];
output_font_change(os, oldFont, context.font);
char const * const * where =
is_known(t.cs(), known_old_font_families);
context.check_layout(os);
- Font const oldFont = context.font;
+ TeXFont const oldFont = context.font;
context.font.init();
context.font.size = oldFont.size;
context.font.family =
char const * const * where =
is_known(t.cs(), known_old_font_series);
context.check_layout(os);
- Font const oldFont = context.font;
+ TeXFont const oldFont = context.font;
context.font.init();
context.font.size = oldFont.size;
context.font.series =
char const * const * where =
is_known(t.cs(), known_old_font_shapes);
context.check_layout(os);
- Font const oldFont = context.font;
+ TeXFont const oldFont = context.font;
context.font.init();
context.font.size = oldFont.size;
context.font.shape =
else if (t.cs() == "\"") {
context.check_layout(os);
string const name = p.verbatim_item();
- if (name == "a") os << 'ä';
- else if (name == "o") os << 'ö';
- else if (name == "u") os << 'ü';
- else if (name == "A") os << 'Ä';
- else if (name == "O") os << 'Ö';
- else if (name == "U") os << 'Ü';
+ if (name == "a") os << '\xe4';
+ else if (name == "o") os << '\xf6';
+ else if (name == "u") os << '\xfc';
+ else if (name == "A") os << '\xc4';
+ else if (name == "O") os << '\xd6';
+ else if (name == "U") os << '\xdc';
else handle_ert(os, "\"{" + name + "}", context);
}
// subset of LaTeX, so don't parse anything here,
// but use the raw argument.
// Otherwise we would convert \~{\i} wrongly.
- // This will of course not translate \~{\ss} to \~{ß},
+ // This will of course not translate \~{\ss} to \~{ß},
// but that does at least compile and does only look
// strange on screen.
context.check_layout(os);
else if (t.cs() == "ss") {
context.check_layout(os);
- os << "ß";
+ os << "\xdf";
skip_braces(p); // eat {}
}
else if (t.cs() == "i" || t.cs() == "j" || t.cs() == "l" ||
- t.cs() == "L") {
+ t.cs() == "L") {
context.check_layout(os);
os << "\\i \\" << t.cs() << "{}\n";
skip_braces(p); // eat {}
// therefore path is only used for testing
// FIXME UNICODE encoding of filename and path may be
// wrong (makeAbsPath expects utf8)
- if (t.cs() == "include" &&
- !fs::exists(makeAbsPath(filename, path).toFilesystemEncoding())) {
+ if ((t.cs() == "include" || t.cs() == "input") &&
+ !makeAbsPath(filename, path).exists()) {
// The file extension is probably missing.
// Now try to find it out.
string const tex_name =
}
// FIXME UNICODE encoding of filename and path may be
// wrong (makeAbsPath expects utf8)
- if (fs::exists(makeAbsPath(filename, path).toFilesystemEncoding())) {
+ if (makeAbsPath(filename, path).exists()) {
string const abstexname =
makeAbsPath(filename, path).absFilename();
string const abslyxname =
string const ert = name + '{' + command + '}' +
opt1 + opt2 +
'{' + p.verbatim_item() + '}';
- handle_ert(os, ert, context);
+
+ context.check_layout(os);
+ begin_inset(os, "FormulaMacro");
+ os << "\n" << ert;
+ end_inset(os);
}
else if (t.cs() == "vspace") {