The SWORD Project  1.9.0.svnversion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
gbflatex.cpp
Go to the documentation of this file.
1 /******************************************************************************
2  *
3  * gbflatex.cpp - GBF to LaTeX
4  *
5  * $Id: gbflatex.cpp 3547 2017-12-10 05:06:48Z scribe $
6  *
7  * Copyright 2011-2014 CrossWire Bible Society (http://www.crosswire.org)
8  * CrossWire Bible Society
9  * P. O. Box 2528
10  * Tempe, AZ 85280-2528
11  *
12  * This program is free software; you can redistribute it and/or modify it
13  * under the terms of the GNU General Public License as published by the
14  * Free Software Foundation version 2.
15  *
16  * This program is distributed in the hope that it will be useful, but
17  * WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * General Public License for more details.
20  *
21  */
22 
23 
24 #include <stdlib.h>
25 #include <gbflatex.h>
26 #include <swmodule.h>
27 #include <utilxml.h>
28 #include <versekey.h>
29 #include <ctype.h>
30 #include <url.h>
31 
33 
34 const char *GBFLaTeX::getHeader() const {
35  return "\\usepackage{color}";
36 }
37 
39  if (module) {
40  version = module->getName();
41  }
42 }
43 
45  setTokenStart("<");
46  setTokenEnd(">");
47 
49 
50  //addTokenSubstitute("Rf", ")</small></font>");
51  addTokenSubstitute("FA", "{\\color{maroon}"); // for ASV footnotes to mark text
52  addTokenSubstitute("Rx", "}");
53  addTokenSubstitute("FI", "\\emph{"); // italics begin
54  addTokenSubstitute("Fi", "}");
55  addTokenSubstitute("FB", "\\bold{"); // bold begin
56  addTokenSubstitute("Fb", "}");
57  addTokenSubstitute("FR", "{\\swordwoj{"); // words of Jesus begin
58  addTokenSubstitute("Fr", "}");
59  addTokenSubstitute("FU", "\\underline{"); // underline begin
60  addTokenSubstitute("Fu", "}");
61  addTokenSubstitute("FO", "\\begin{quote}"); // Old Testament quote begin
62  addTokenSubstitute("Fo", "\\end{quote}");
63  addTokenSubstitute("FS", "\\textsuperscript{"); // Superscript begin// Subscript begin
64  addTokenSubstitute("Fs", "}");
65  addTokenSubstitute("FV", "\\textsubscript{"); // Subscript begin
66  addTokenSubstitute("Fv", "}");
67  addTokenSubstitute("TT", "\\section*{"); // Book title begin
68  addTokenSubstitute("Tt", "}");
69  addTokenSubstitute("PP", "\\begin{swordpoetry}"); // poetry begin
70  addTokenSubstitute("Pp", "\\end{swordpoetry}");
71  addTokenSubstitute("Fn", ""); // font end
72  addTokenSubstitute("CL", "\\\\"); // new line
73  addTokenSubstitute("CM", "\\\\"); // paragraph <!P> is a non showing comment that can be changed in the front end to <P> if desired
74  addTokenSubstitute("CG", ""); // ???
75  addTokenSubstitute("CT", ""); // ???
76  addTokenSubstitute("JR", "{\\raggedright{}"); // right align begin
77  addTokenSubstitute("JC", "{\\raggedcenter{}"); // center align begin
78  addTokenSubstitute("JL", "}"); // align end
79 
80  renderNoteNumbers = false;
81 }
82 
83 
84 bool GBFLaTeX::handleToken(SWBuf &buf, const char *token, BasicFilterUserData *userData) {
85  const char *tok;
86  MyUserData *u = (MyUserData *)userData;
87 
88  if (!substituteToken(buf, token)) {
89  XMLTag tag(token);
90 
91  if (!strncmp(token, "WG", 2)) { // strong's numbers
92  //buf += " <small><em>&lt;<a href=\"type=Strongs value=";
93  buf += " \\swordstrong[Greek]{";
94  for (tok = token+2; *tok; tok++)
95  //if(token[i] != '\"')
96  buf += *tok;
97  buf += ", ";
98  for (tok = token + 2; *tok; tok++)
99  //if(token[i] != '\"')
100  buf += *tok;
101  buf += "}";
102  }
103  else if (!strncmp(token, "WH", 2)) { // strong's numbers
104  buf += " \\swordstrong[Hebrew]{";
105  for (tok = token+2; *tok; tok++)
106  //if(token[i] != '\"')
107  buf += *tok;
108  buf += ", ";
109  for (tok = token + 2; *tok; tok++)
110  //if(token[i] != '\"')
111  buf += *tok;
112  buf += "}";
113  }
114  else if (!strncmp(token, "WTG", 3)) { // strong's numbers tense
115  buf += " \\swordstrong[Greektense]{";
116  for (tok = token + 3; *tok; tok++)
117  if(*tok != '\"')
118  buf += *tok;
119  buf += ", ";
120  for (tok = token + 3; *tok; tok++)
121  if(*tok != '\"')
122  buf += *tok;
123  buf += "}";
124  }
125  else if (!strncmp(token, "WTH", 3)) { // strong's numbers tense
126  buf += " \\swordstrong[Hebrewtense]{";
127  for (tok = token + 3; *tok; tok++)
128  if(*tok != '\"')
129  buf += *tok;
130  buf += ",";
131  for (tok = token + 3; *tok; tok++)
132  if(*tok != '\"')
133  buf += *tok;
134  buf += "}";
135  }
136 
137  else if (!strncmp(token, "WT", 2) && strncmp(token, "WTH", 3) && strncmp(token, "WTG", 3)) { // morph tags
138  buf += " \\swordmorph{";
139 
140  for (tok = token + 2; *tok; tok++)
141  if(*tok != '\"')
142  buf += *tok;
143  buf += ", >";
144  for (tok = token + 2; *tok; tok++)
145  if(*tok != '\"')
146  buf += *tok;
147  buf += "}";
148  }
149 
150  else if (!strcmp(tag.getName(), "RX")) {
151  buf += "\\swordxref{";
152  for (tok = token + 3; *tok; tok++) {
153  if(*tok != '<' && *tok+1 != 'R' && *tok+2 != 'x') {
154  buf += *tok;
155  }
156  else {
157  break;
158  }
159  }
160  buf += "}";
161  }
162  else if (!strcmp(tag.getName(), "RF")) {
163  SWBuf type = tag.getAttribute("type");
164  SWBuf footnoteNumber = tag.getAttribute("swordFootnote");
165  SWBuf noteName = tag.getAttribute("n");
166  if (u->vkey) {
167 
168  buf.appendFormatted("\\swordfootnote{%s}{%s}{%s}{",
169  footnoteNumber.c_str(),
170  u->version.c_str(),
171  u->vkey->getText()).c_str();
172  }
173  u->suspendTextPassThru = false;
174  }
175  else if (!strcmp(tag.getName(), "Rf")) {
176  u->suspendTextPassThru = false;
177  buf += "}";
178  }
179  else if (!strncmp(token, "FN", 2)) {
180  buf += "\\swordfont{";
181  for (tok = token + 2; *tok; tok++)
182  if(*tok != '\"')
183  buf += *tok;
184  buf += "}";
185  }
186 
187  else if (!strncmp(token, "CA", 2)) { // ASCII value
188  buf += (char)atoi(&token[2]);
189  }
190 
191  else {
192  return false;
193  }
194  }
195  return true;
196 }
197 
const char * getName() const
Definition: swmodule.cpp:204
#define SWORD_NAMESPACE_START
Definition: defs.h:39
SWBuf & appendFormatted(const char *format,...)
Definition: swbuf.cpp:81
void setTokenEnd(const char *tokenEnd)
Definition: swbuf.h:47
const char * getName() const
Definition: utilxml.h:58
SWText * module
Definition: osis2mod.cpp:105
Definition: utilxml.h:38
virtual bool handleToken(SWBuf &buf, const char *token, BasicFilterUserData *userData)
Definition: gbflatex.cpp:84
GBFLaTeX()
Definition: gbflatex.cpp:44
void setTokenCaseSensitive(bool val)
bool substituteToken(SWBuf &buf, const char *token)
const VerseKey * vkey
Definition: swbasicfilter.h:44
virtual const char * getText() const
Definition: versekey.cpp:1242
void setTokenStart(const char *tokenStart)
const char * c_str() const
Definition: swbuf.h:158
virtual const char * getHeader() const
Definition: gbflatex.cpp:34
MyUserData(const SWModule *module, const SWKey *key)
Definition: gbflatex.cpp:38
bool renderNoteNumbers
Definition: gbflatex.h:34
const char * getAttribute(const char *attribName, int partNum=-1, char partSplit= '|') const
Definition: utilxml.cpp:230
void addTokenSubstitute(const char *findString, const char *replaceString)
#define SWORD_NAMESPACE_END
Definition: defs.h:40
Definition: swkey.h:77