latexdocvisitor.cpp 44.7 KB
Newer Older
1 2
/******************************************************************************
 *
3
 * 
4 5
 *
 *
Dimitri van Heesch's avatar
Dimitri van Heesch committed
6
 * Copyright (C) 1997-2013 by Dimitri van Heesch.
7 8 9 10 11 12 13 14 15 16 17
 *
 * Permission to use, copy, modify, and distribute this software and its
 * documentation under the terms of the GNU General Public License is hereby 
 * granted. No representations are made about the suitability of this software 
 * for any purpose. It is provided "as is" without express or implied warranty.
 * See the GNU General Public License for more details.
 *
 * Documents produced by Doxygen are derivative works derived from the
 * input used in their production; they are not affected by this license.
 *
 */
18
#include "htmlattrib.h"
19
#include <qfileinfo.h> 
20
#include "latexdocvisitor.h"
21 22 23 24 25
#include "docparser.h"
#include "language.h"
#include "doxygen.h"
#include "outputgen.h"
#include "dot.h"
26
#include "util.h"
27
#include "message.h"
28
#include "parserintf.h"
29
#include "msc.h"
30
#include "cite.h"
31 32
#include "filedef.h"
#include "config.h"
33

34
static QCString escapeLabelName(const char *s)
35
{
36
  QCString result;
37 38 39 40 41 42 43
  const char *p=s;
  char c;
  while ((c=*p++))
  {
    switch (c)
    {
      case '%': result+="\\%"; break;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
44
      case '|': result+="\\texttt{\"|}"; break;
45 46 47 48 49 50 51
      case '!': result+="\"!"; break;
      default: result+=c;
    }
  }
  return result;
}

52 53 54 55 56 57
const int maxLevels=5;
static const char *secLabels[maxLevels] = 
   { "section","subsection","subsubsection","paragraph","subparagraph" };

static const char *getSectionName(int level)
{
58
  static bool compactLatex = Config_getBool("COMPACT_LATEX");
59
  int l = level;
60
  if (compactLatex) l++;
61 62 63 64
  if (Doxygen::insideMainPage) l--;
  return secLabels[QMIN(maxLevels-1,l)];
}

65
QCString LatexDocVisitor::escapeMakeIndexChars(const char *s)
66
{
67
  QCString result;
68 69 70 71 72 73 74 75 76 77
  const char *p=s;
  char str[2]; str[1]=0;
  char c;
  while ((c=*p++))
  {
    switch (c)
    {
      case '!': m_t << "\"!"; break;
      case '"': m_t << "\"\""; break;
      case '@': m_t << "\"@"; break;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
78
      case '|': m_t << "\\texttt{\"|}"; break;
79 80 81 82 83 84 85 86
      case '[': m_t << "["; break;
      case ']': m_t << "]"; break;
      default:  str[0]=c; filter(str); break;
    }
  }
  return result;
}

87

88
LatexDocVisitor::LatexDocVisitor(FTextStream &t,CodeOutputInterface &ci,
89
                                 const char *langExt,bool insideTabbing) 
90
  : DocVisitor(DocVisitor_Latex), m_t(t), m_ci(ci), m_insidePre(FALSE), 
91
    m_insideItem(FALSE), m_hide(FALSE), m_insideTabbing(insideTabbing),
Dimitri van Heesch's avatar
Dimitri van Heesch committed
92 93
    m_insideTable(FALSE), m_langExt(langExt), m_currentColumn(0), 
    m_inRowspan(FALSE), m_inColspan(FALSE)
94
{
Dimitri van Heesch's avatar
Dimitri van Heesch committed
95
  m_rowSpans.setAutoDelete(TRUE);
96 97 98 99 100 101 102 103 104
}

  //--------------------------------------
  // visitor functions for leaf nodes
  //--------------------------------------

void LatexDocVisitor::visit(DocWord *w)
{
  if (m_hide) return;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
105
  filter(w->word());
106 107 108 109 110 111
}

void LatexDocVisitor::visit(DocLinkedWord *w)
{
  if (m_hide) return;
  startLink(w->ref(),w->file(),w->anchor());
Dimitri van Heesch's avatar
Dimitri van Heesch committed
112
  filter(w->word());
Dimitri van Heesch's avatar
Dimitri van Heesch committed
113
  endLink(w->ref(),w->file(),w->anchor());
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
}

void LatexDocVisitor::visit(DocWhiteSpace *w)
{
  if (m_hide) return;
  if (m_insidePre)
  {
    m_t << w->chars();
  }
  else
  {
    m_t << " ";
  }
}

void LatexDocVisitor::visit(DocSymbol *s)
{
  if (m_hide) return;
  switch(s->symbol())
  {
Dimitri van Heesch's avatar
Dimitri van Heesch committed
134
    case DocSymbol::BSlash:  m_t << "\\textbackslash{}"; break;
135
    case DocSymbol::At:      m_t << "@"; break;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
136 137 138
    case DocSymbol::Less:    if (m_insidePre) m_t << "<"; else m_t << "$<$"; 
                             break;
    case DocSymbol::Greater: if (m_insidePre) m_t << ">"; else m_t << "$>$"; break;
139 140 141
    case DocSymbol::Amp:     m_t << "\\&"; break;
    case DocSymbol::Dollar:  m_t << "\\$"; break;
    case DocSymbol::Hash:    m_t << "\\#"; break;
142
    case DocSymbol::DoubleColon:  m_t << "::"; break;
143
    case DocSymbol::Percent: m_t << "\\%"; break;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
144
    case DocSymbol::Pipe:    m_t << "$|$"; break;
145
    case DocSymbol::Copy:    m_t << "\\copyright"; break;
146 147
    case DocSymbol::Tm:      m_t << "\\texttrademark"; break;
    case DocSymbol::Reg:     m_t << "\\textregistered"; break;
148
    case DocSymbol::Apos:    m_t << "'"; break;
149 150 151 152 153 154 155
    case DocSymbol::Quot:    m_t << "\""; break;
    case DocSymbol::Lsquo:   m_t << "`"; break;
    case DocSymbol::Rsquo:   m_t << "'"; break;
    case DocSymbol::Ldquo:   m_t << "``"; break;
    case DocSymbol::Rdquo:   m_t << "''"; break;
    case DocSymbol::Ndash:   m_t << "--"; break;
    case DocSymbol::Mdash:   m_t << "---"; break;
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
    case DocSymbol::Uml:     
                             if (s->letter()=='i') 
                               m_t << "\\\"{\\i}"; 
                             else                  
                               m_t << "\\\"{" << s->letter() << "}"; 
                             break;
    case DocSymbol::Acute:   
                             if (s->letter()=='i') 
                               m_t << "\\'{\\i}"; 
                             else                  
                               m_t << "\\'{" << s->letter() << "}"; 
                             break;
    case DocSymbol::Grave:   
                             if (s->letter()=='i') 
                               m_t << "\\`{\\i}"; 
                             else                  
                               m_t << "\\`{" << s->letter() << "}"; 
                             break;
    case DocSymbol::Circ:    
                             if (s->letter()=='i') 
                               m_t << "\\^{\\i}"; 
                             else                  
                               m_t << "\\^{" << s->letter() << "}"; 
                             break;
180
    case DocSymbol::Slash:   if (tolower(s->letter())=='o')
181
                               m_t << "{\\" << s->letter() << "}";
182 183 184
                             else
                               m_t << s->letter();
                             break;
185
    case DocSymbol::Tilde:   m_t << "\\~{"  << s->letter() << "}"; break;
186
    case DocSymbol::Szlig:   m_t << "{\\ss}"; break;
187 188
    case DocSymbol::Cedil:   m_t << "\\c{" << s->letter() << "}"; break;
    case DocSymbol::Ring:    m_t << "\\" << s->letter() << s->letter(); break;
189
    case DocSymbol::Nbsp:    m_t << "~"; break;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
190 191
    case DocSymbol::AElig:   m_t << "{\\AE}"; break;
    case DocSymbol::Aelig:   m_t << "{\\ae}"; break;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258
    case DocSymbol::GrkGamma:      m_t << "{$\\Gamma$}"; break;
    case DocSymbol::GrkDelta:      m_t << "{$\\Delta$}"; break;
    case DocSymbol::GrkTheta:      m_t << "{$\\Theta$}"; break;
    case DocSymbol::GrkLambda:     m_t << "{$\\Lambda$}"; break;
    case DocSymbol::GrkXi:         m_t << "{$\\Xi$}"; break;
    case DocSymbol::GrkPi:         m_t << "{$\\Pi$}"; break;
    case DocSymbol::GrkSigma:      m_t << "{$\\Sigma$}"; break;
    case DocSymbol::GrkUpsilon:    m_t << "{$\\Upsilon$}"; break;
    case DocSymbol::GrkPhi:        m_t << "{$\\Phi$}"; break;
    case DocSymbol::GrkPsi:        m_t << "{$\\Psi$}"; break;
    case DocSymbol::GrkOmega:      m_t << "{$\\Omega$}"; break;
    case DocSymbol::Grkalpha:      m_t << "{$\\alpha$}"; break;
    case DocSymbol::Grkbeta:       m_t << "{$\\beta$}"; break;
    case DocSymbol::Grkgamma:      m_t << "{$\\gamma$}"; break;
    case DocSymbol::Grkdelta:      m_t << "{$\\delta$}"; break;
    case DocSymbol::Grkepsilon:    m_t << "{$\\varepsilon$}"; break;
    case DocSymbol::Grkzeta:       m_t << "{$\\zeta$}"; break;
    case DocSymbol::Grketa:        m_t << "{$\\eta$}"; break;
    case DocSymbol::Grktheta:      m_t << "{$\\theta$}"; break;
    case DocSymbol::Grkiota:       m_t << "{$\\iota$}"; break;
    case DocSymbol::Grkkappa:      m_t << "{$\\kappa$}"; break;
    case DocSymbol::Grklambda:     m_t << "{$\\lambda$}"; break;
    case DocSymbol::Grkmu:         m_t << "{$\\mu$}"; break;
    case DocSymbol::Grknu:         m_t << "{$\\nu$}"; break;
    case DocSymbol::Grkxi:         m_t << "{$\\xi$}"; break;
    case DocSymbol::Grkpi:         m_t << "{$\\pi$}"; break;
    case DocSymbol::Grkrho:        m_t << "{$\\rho$}"; break;
    case DocSymbol::Grksigma:      m_t << "{$\\sigma$}"; break;
    case DocSymbol::Grktau:        m_t << "{$\\tau$}"; break;
    case DocSymbol::Grkupsilon:    m_t << "{$\\upsilon$}"; break;
    case DocSymbol::Grkphi:        m_t << "{$\\varphi$}"; break;
    case DocSymbol::Grkchi:        m_t << "{$\\chi$}"; break;
    case DocSymbol::Grkpsi:        m_t << "{$\\psi$}"; break;
    case DocSymbol::Grkomega:      m_t << "{$\\omega$}"; break;
    case DocSymbol::Grkvarsigma:   m_t << "{$\\varsigma$}"; break;
    case DocSymbol::Section:       m_t << "{$\\S$}"; break;
    case DocSymbol::Degree:        m_t << "\\textdegree"; break;
    case DocSymbol::Prime:         m_t << "'"; break;
    case DocSymbol::DoublePrime:   m_t << "''"; break;
    case DocSymbol::Infinity:      m_t << "{$\\infty$}"; break;
    case DocSymbol::EmptySet:      m_t << "{$\\emptyset$}"; break;
    case DocSymbol::PlusMinus:     m_t << "{$\\pm$}"; break;
    case DocSymbol::Times:         m_t << "{$\\times$}"; break;
    case DocSymbol::Minus:         m_t << "-"; break;
    case DocSymbol::CenterDot:     m_t << "{$\\cdot$}"; break;
    case DocSymbol::Partial:       m_t << "{$\\partial$}"; break;
    case DocSymbol::Nabla:         m_t << "{$\\nabla$}"; break;
    case DocSymbol::SquareRoot:    m_t << "{$\\surd$}"; break;
    case DocSymbol::Perpendicular: m_t << "{$\\perp$}"; break;
    case DocSymbol::Sum:           m_t << "{$\\sum$}"; break;
    case DocSymbol::Integral:      m_t << "{$\\int$}"; break;
    case DocSymbol::Product:       m_t << "{$\\prod$}"; break;
    case DocSymbol::Similar:       m_t << "{$\\sim$}"; break;
    case DocSymbol::Approx:        m_t << "{$\\approx$}"; break;
    case DocSymbol::NotEqual:      m_t << "{$\\ne$}"; break;
    case DocSymbol::Equivalent:    m_t << "{$\\equiv$}"; break;
    case DocSymbol::Proportional:  m_t << "{$\\propto$}"; break;
    case DocSymbol::LessEqual:     m_t << "{$\\le$}"; break;
    case DocSymbol::GreaterEqual:  m_t << "{$\\ge$}"; break;
    case DocSymbol::LeftArrow:     m_t << "{$\\leftarrow$}"; break;
    case DocSymbol::RightArrow:    m_t << "{$\\rightarrow$}"; break;
    case DocSymbol::SetIn:         m_t << "{$\\in$}"; break;
    case DocSymbol::SetNotIn:      m_t << "{$\\notin$}"; break;
    case DocSymbol::LeftCeil:      m_t << "{$\\lceil$}"; break;
    case DocSymbol::RightCeil:     m_t << "{$\\rceil$}"; break;
    case DocSymbol::LeftFloor:     m_t << "{$\\lfloor$}"; break;
    case DocSymbol::RightFloor:    m_t << "{$\\rfloor$}"; break;
259
    default:
260
                             err("unknown symbol found\n");
261 262 263 264 265 266 267 268
  }
}

void LatexDocVisitor::visit(DocURL *u)
{
  if (m_hide) return;
  if (Config_getBool("PDF_HYPERLINKS"))
  {
269 270 271
    m_t << "\\href{";
    if (u->isEmail()) m_t << "mailto:";
    m_t << u->url() << "}";
272
  }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
273
  m_t << "{\\tt ";
274 275
  filter(u->url());
  m_t << "}";
276 277 278 279 280
}

void LatexDocVisitor::visit(DocLineBreak *)
{
  if (m_hide) return;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
281 282
  if (m_insideTable) m_t << "\\newline\n";
  else m_t << "\\par\n";
283 284 285 286 287 288 289 290 291 292 293 294 295 296
}

void LatexDocVisitor::visit(DocHorRuler *)
{
  if (m_hide) return;
  m_t << "\n\n";
}

void LatexDocVisitor::visit(DocStyleChange *s)
{
  if (m_hide) return;
  switch (s->style())
  {
    case DocStyleChange::Bold:
297
      if (s->enable()) m_t << "{\\bfseries ";      else m_t << "}";
298 299
      break;
    case DocStyleChange::Italic:
Dimitri van Heesch's avatar
Dimitri van Heesch committed
300
      if (s->enable()) m_t << "{\\itshape ";     else m_t << "}";
301 302
      break;
    case DocStyleChange::Code:
303
      if (s->enable()) m_t << "{\\ttfamily ";   else m_t << "}";
304 305 306 307 308 309 310 311 312 313 314
      break;
    case DocStyleChange::Subscript:
      if (s->enable()) m_t << "$_{\\mbox{";    else m_t << "}}$ ";
      break;
    case DocStyleChange::Superscript:
      if (s->enable()) m_t << "$^{\\mbox{";    else m_t << "}}$ ";
      break;
    case DocStyleChange::Center:
      if (s->enable()) m_t << "\\begin{center}"; else m_t << "\\end{center} ";
      break;
    case DocStyleChange::Small:
315
      if (s->enable()) m_t << "\n\\footnotesize ";  else m_t << "\n\\normalsize ";
316
      break;
317 318 319
    case DocStyleChange::Preformatted:
      if (s->enable()) 
      {
320
        m_t << "\n\\begin{DoxyPre}";
321 322 323 324 325
        m_insidePre=TRUE;
      }
      else
      {
        m_insidePre=FALSE;
326
        m_t << "\\end{DoxyPre}\n";
327 328
      }
      break;
329 330
    case DocStyleChange::Div:  /* HTML only */ break;
    case DocStyleChange::Span: /* HTML only */ break;
331 332 333 334 335 336
  }
}

void LatexDocVisitor::visit(DocVerbatim *s)
{
  if (m_hide) return;
337 338 339 340 341
  QCString lang = m_langExt;
  if (!s->language().isEmpty()) // explicit language setting
  {
    lang = s->language();
  }
342 343
  switch(s->type())
  {
Dimitri van Heesch's avatar
Dimitri van Heesch committed
344
    case DocVerbatim::Code: 
345
      {
346
        m_t << "\n\\begin{DoxyCode}\n";
347 348 349
        Doxygen::parserManager->getParser(lang)
                              ->parseCode(m_ci,s->context(),s->text(),
                                          s->isExample(),s->exampleFile());
350
        m_t << "\\end{DoxyCode}\n";
351
      }
352 353
      break;
    case DocVerbatim::Verbatim: 
354
      m_t << "\\begin{DoxyVerb}";
355
      m_t << s->text();
356
      m_t << "\\end{DoxyVerb}\n";
357 358
      break;
    case DocVerbatim::HtmlOnly: 
359
    case DocVerbatim::XmlOnly: 
360
    case DocVerbatim::ManOnly: 
361 362
    case DocVerbatim::RtfOnly:
    case DocVerbatim::DocbookOnly:
363 364 365 366 367
      /* nothing */ 
      break;
    case DocVerbatim::LatexOnly: 
      m_t << s->text(); 
      break;
368 369 370 371 372
    case DocVerbatim::Dot: 
      {
        static int dotindex = 1;
        QCString fileName(4096);

373
        fileName.sprintf("%s%d%s", 
374
            (Config_getString("LATEX_OUTPUT")+"/inline_dotgraph_").data(), 
375 376
            dotindex++,
            ".dot"
377 378 379 380 381 382 383 384 385 386 387 388 389 390
           );
        QFile file(fileName);
        if (!file.open(IO_WriteOnly))
        {
          err("Could not open file %s for writing\n",fileName.data());
        }
        file.writeBlock( s->text(), s->text().length() );
        file.close();

        m_t << "\\begin{center}\n";
        startDotFile(fileName,"","",FALSE);
        endDotFile(FALSE);
        m_t << "\\end{center}\n";

391
        if (Config_getBool("DOT_CLEANUP")) file.remove();
392 393
      }
      break;
394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420
    case DocVerbatim::Msc: 
      {
        static int mscindex = 1;
        QCString baseName(4096);

        baseName.sprintf("%s%d", 
            (Config_getString("LATEX_OUTPUT")+"/inline_mscgraph_").data(), 
            mscindex++
           );
        QFile file(baseName+".msc");
        if (!file.open(IO_WriteOnly))
        {
          err("Could not open file %s.msc for writing\n",baseName.data());
        }
        QCString text = "msc {";
        text+=s->text();
        text+="}";
        file.writeBlock( text, text.length() );
        file.close();

        m_t << "\\begin{center}\n";
        writeMscFile(baseName);
        m_t << "\\end{center}\n";

        if (Config_getBool("DOT_CLEANUP")) file.remove();
      }
      break;
421 422 423 424 425 426
  }
}

void LatexDocVisitor::visit(DocAnchor *anc)
{
  if (m_hide) return;
427
  m_t << "\\label{" << stripPath(anc->file()) << "_" << anc->anchor() << "}%" << endl;
428 429
  if (!anc->file().isEmpty() && Config_getBool("PDF_HYPERLINKS")) 
  {
430
    m_t << "\\hypertarget{" << stripPath(anc->file()) << "_" << anc->anchor() 
431
      << "}{}%" << endl;
432 433 434 435 436 437 438 439
  }    
}

void LatexDocVisitor::visit(DocInclude *inc)
{
  if (m_hide) return;
  switch(inc->type())
  {
440 441
    case DocInclude::IncWithLines:
      { 
442
         m_t << "\n\\begin{DoxyCodeInclude}\n";
443
         QFileInfo cfi( inc->file() );
444
         FileDef fd( cfi.dirPath().utf8(), cfi.fileName().utf8() );
445
         Doxygen::parserManager->getParser(inc->extension())
446
                               ->parseCode(m_ci,inc->context(),
447
                                           inc->text(),
448 449
                                           inc->isExample(),
                                           inc->exampleFile(), &fd);
450
         m_t << "\\end{DoxyCodeInclude}" << endl;
451 452
      }
      break;    
453
    case DocInclude::Include: 
454
      m_t << "\n\\begin{DoxyCodeInclude}\n";
455
      Doxygen::parserManager->getParser(inc->extension())
456
                            ->parseCode(m_ci,inc->context(),
457
                                        inc->text(),inc->isExample(),
458
                                        inc->exampleFile());
459
      m_t << "\\end{DoxyCodeInclude}\n";
460 461 462 463 464 465
      break;
    case DocInclude::DontInclude: 
      break;
    case DocInclude::HtmlInclude: 
      break;
    case DocInclude::VerbInclude: 
466
      m_t << "\n\\begin{DoxyVerbInclude}\n";
467
      m_t << inc->text();
468
      m_t << "\\end{DoxyVerbInclude}\n";
469
      break;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
470 471 472 473 474 475 476 477 478 479 480 481 482
    case DocInclude::Snippet:
      {
         m_t << "\n\\begin{DoxyCodeInclude}\n";
         Doxygen::parserManager->getParser(inc->extension())
                               ->parseCode(m_ci,
                                           inc->context(),
                                           extractBlock(inc->text(),inc->blockId()),
                                           inc->isExample(),
                                           inc->exampleFile()
                                          );
         m_t << "\\end{DoxyCodeInclude}" << endl;
      }
      break;
483 484 485 486 487
  }
}

void LatexDocVisitor::visit(DocIncOperator *op)
{
488 489
  //printf("DocIncOperator: type=%d first=%d, last=%d text=`%s'\n",
  //    op->type(),op->isFirst(),op->isLast(),op->text().data());
490 491
  if (op->isFirst()) 
  {
492
    if (!m_hide) m_t << "\n\\begin{DoxyCodeInclude}\n";
493
    pushEnabled();
494 495 496 497
    m_hide = TRUE;
  }
  if (op->type()!=DocIncOperator::Skip) 
  {
Dimitri van Heesch's avatar
Dimitri van Heesch committed
498
    popEnabled();
499 500 501
    if (!m_hide) 
    {
      Doxygen::parserManager->getParser(m_langExt)
502
                            ->parseCode(m_ci,op->context(),op->text(),
503 504
                                        op->isExample(),op->exampleFile());
    }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
505 506
    pushEnabled();
    m_hide=TRUE;
507 508 509
  }
  if (op->isLast())  
  {
510
    popEnabled();
511
    if (!m_hide) m_t << "\n\\end{DoxyCodeInclude}\n";
512 513 514
  }
  else
  {
Dimitri van Heesch's avatar
Dimitri van Heesch committed
515
    if (!m_hide) m_t << endl;
516 517 518 519 520 521 522 523 524
  }
}

void LatexDocVisitor::visit(DocFormula *f)
{
  if (m_hide) return;
  m_t << f->text();
}

525 526
void LatexDocVisitor::visit(DocIndexEntry *i)
{
527
  if (m_hide) return;
528 529 530 531 532
  m_t << "\\index{" << escapeLabelName(i->entry()) << "@{";
  escapeMakeIndexChars(i->entry());
  m_t << "}}";
}

533 534 535 536
void LatexDocVisitor::visit(DocSimpleSectSep *)
{
}

537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554
void LatexDocVisitor::visit(DocCite *cite)
{
  if (m_hide) return;
  if (!cite->file().isEmpty()) 
  {
    //startLink(cite->ref(),cite->file(),cite->anchor());
    QCString anchor = cite->anchor();
    anchor = anchor.mid(CiteConsts::anchorPrefix.length()); // strip prefix
    m_t << "\\cite{" << anchor << "}";
  }
  else
  {
    m_t << "{\\bfseries [";
    filter(cite->text());
    m_t << "]}";
  }
}

555 556 557 558 559 560
//--------------------------------------
// visitor functions for compound nodes
//--------------------------------------

void LatexDocVisitor::visitPre(DocAutoList *l)
{
561
  if (m_hide) return;
562 563
  if (l->isEnumList())
  {
564
    m_t << "\n\\begin{DoxyEnumerate}";
565 566 567
  }
  else
  {
568
    m_t << "\n\\begin{DoxyItemize}";
569 570 571 572 573
  }
}

void LatexDocVisitor::visitPost(DocAutoList *l)
{
574
  if (m_hide) return;
575 576
  if (l->isEnumList())
  {
577
    m_t << "\n\\end{DoxyEnumerate}";
578 579 580
  }
  else
  {
581
    m_t << "\n\\end{DoxyItemize}";
582 583 584 585 586
  }
}

void LatexDocVisitor::visitPre(DocAutoListItem *)
{
587
  if (m_hide) return;
588
  m_t << "\n\\item ";
589 590 591 592 593 594 595 596 597 598 599 600
}

void LatexDocVisitor::visitPost(DocAutoListItem *) 
{
}

void LatexDocVisitor::visitPre(DocPara *) 
{
}

void LatexDocVisitor::visitPost(DocPara *p)
{
601
  if (m_hide) return;
602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618
  if (!p->isLast() &&            // omit <p> for last paragraph
      !(p->parent() &&           // and for parameter sections
        p->parent()->kind()==DocNode::Kind_ParamSect
       )
     ) m_t << endl << endl;
}

void LatexDocVisitor::visitPre(DocRoot *)
{
}

void LatexDocVisitor::visitPost(DocRoot *)
{
}

void LatexDocVisitor::visitPre(DocSimpleSect *s)
{
619
  if (m_hide) return;
620 621
  switch(s->type())
  {
622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653
    case DocSimpleSect::See:
      m_t << "\\begin{DoxySeeAlso}{";
      filter(theTranslator->trSeeAlso());
      break;
    case DocSimpleSect::Return:
      m_t << "\\begin{DoxyReturn}{";
      filter(theTranslator->trReturns());
      break;
    case DocSimpleSect::Author:
      m_t << "\\begin{DoxyAuthor}{";
      filter(theTranslator->trAuthor(TRUE,TRUE));
      break;
    case DocSimpleSect::Authors:
      m_t << "\\begin{DoxyAuthor}{";
      filter(theTranslator->trAuthor(TRUE,FALSE));
      break;
    case DocSimpleSect::Version:
      m_t << "\\begin{DoxyVersion}{";
      filter(theTranslator->trVersion());
      break;
    case DocSimpleSect::Since:
      m_t << "\\begin{DoxySince}{";
      filter(theTranslator->trSince());
      break;
    case DocSimpleSect::Date:
      m_t << "\\begin{DoxyDate}{";
      filter(theTranslator->trDate());
      break;
    case DocSimpleSect::Note:
      m_t << "\\begin{DoxyNote}{";
      filter(theTranslator->trNote());
      break;
654
    case DocSimpleSect::Warning:
655 656 657
      m_t << "\\begin{DoxyWarning}{";
      filter(theTranslator->trWarning());
      break;
658
    case DocSimpleSect::Pre:
659 660 661
      m_t << "\\begin{DoxyPrecond}{";
      filter(theTranslator->trPrecondition());
      break;
662
    case DocSimpleSect::Post:
663 664 665
      m_t << "\\begin{DoxyPostcond}{";
      filter(theTranslator->trPostcondition());
      break;
666 667
    case DocSimpleSect::Copyright:
      m_t << "\\begin{DoxyCopyright}{";
668
      filter(theTranslator->trCopyright());
669
      break;
670
    case DocSimpleSect::Invar:
671 672 673
      m_t << "\\begin{DoxyInvariant}{";
      filter(theTranslator->trInvariant());
      break;
674
    case DocSimpleSect::Remark:
675 676 677
      m_t << "\\begin{DoxyRemark}{";
      filter(theTranslator->trRemarks());
      break;
678
    case DocSimpleSect::Attention:
679 680 681 682 683 684
      m_t << "\\begin{DoxyAttention}{";
      filter(theTranslator->trAttention());
      break;
    case DocSimpleSect::User:
      m_t << "\\begin{DoxyParagraph}{";
      break;
685 686 687
    case DocSimpleSect::Rcs: 
      m_t << "\\begin{DoxyParagraph}{";
      break;
688 689 690 691
    case DocSimpleSect::Unknown:  break;
  }

  // special case 1: user defined title
692
  if (s->type()!=DocSimpleSect::User && s->type()!=DocSimpleSect::Rcs)
693
  {
694
    m_t << "}\n";
695
  }
696 697 698 699
  else
  {
    m_insideItem=TRUE;
  }
700 701
}

702
void LatexDocVisitor::visitPost(DocSimpleSect *s)
703
{
704
  if (m_hide) return;
705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739
  switch(s->type())
  {
    case DocSimpleSect::See:
      m_t << "\n\\end{DoxySeeAlso}\n";
      break;
    case DocSimpleSect::Return:
      m_t << "\n\\end{DoxyReturn}\n";
      break;
    case DocSimpleSect::Author:
      m_t << "\n\\end{DoxyAuthor}\n";
      break;
    case DocSimpleSect::Authors:
      m_t << "\n\\end{DoxyAuthor}\n";
      break;
    case DocSimpleSect::Version:
      m_t << "\n\\end{DoxyVersion}\n";
      break;
    case DocSimpleSect::Since:
      m_t << "\n\\end{DoxySince}\n";
      break;
    case DocSimpleSect::Date:
      m_t << "\n\\end{DoxyDate}\n";
      break;
    case DocSimpleSect::Note:
      m_t << "\n\\end{DoxyNote}\n";
      break;
    case DocSimpleSect::Warning:
      m_t << "\n\\end{DoxyWarning}\n";
      break;
    case DocSimpleSect::Pre:
      m_t << "\n\\end{DoxyPrecond}\n";
      break;
    case DocSimpleSect::Post:
      m_t << "\n\\end{DoxyPostcond}\n";
      break;
740 741 742
    case DocSimpleSect::Copyright:
      m_t << "\n\\end{DoxyCopyright}\n";
      break;
743 744 745 746 747 748 749 750 751 752 753 754
    case DocSimpleSect::Invar:
      m_t << "\n\\end{DoxyInvariant}\n";
      break;
    case DocSimpleSect::Remark:
      m_t << "\n\\end{DoxyRemark}\n";
      break;
    case DocSimpleSect::Attention:
      m_t << "\n\\end{DoxyAttention}\n";
      break;
    case DocSimpleSect::User:
      m_t << "\n\\end{DoxyParagraph}\n";
      break;
755 756 757
    case DocSimpleSect::Rcs: 
      m_t << "\n\\end{DoxyParagraph}\n";
      break;
758 759 760
    default:
      break;
  }
761 762 763 764 765 766 767 768
}

void LatexDocVisitor::visitPre(DocTitle *)
{
}

void LatexDocVisitor::visitPost(DocTitle *)
{
769
  if (m_hide) return;
770
  m_insideItem=FALSE;
771
  m_t << "}\n";
772 773 774 775
}

void LatexDocVisitor::visitPre(DocSimpleList *)
{
776
  if (m_hide) return;
777
  m_t << "\\begin{DoxyItemize}" << endl;
778 779 780 781
}

void LatexDocVisitor::visitPost(DocSimpleList *)
{
782
  if (m_hide) return;
783
  m_t << "\\end{DoxyItemize}" << endl;
784 785 786 787
}

void LatexDocVisitor::visitPre(DocSimpleListItem *)
{
788
  if (m_hide) return;
789 790 791 792 793 794 795 796 797
  m_t << "\\item ";
}

void LatexDocVisitor::visitPost(DocSimpleListItem *) 
{
}

void LatexDocVisitor::visitPre(DocSection *s)
{
798
  if (m_hide) return;
799 800
  if (Config_getBool("PDF_HYPERLINKS"))
  {
801
    m_t << "\\hypertarget{" << stripPath(s->file()) << "_" << s->anchor() << "}{}";
802
  }
803
  m_t << "\\" << getSectionName(s->level()) << "{";
804
  filter(convertCharEntitiesToUTF8(s->title().data()));
805
  m_t << "}\\label{" << stripPath(s->file()) << "_" << s->anchor() << "}" << endl;
806 807 808 809 810 811 812 813
}

void LatexDocVisitor::visitPost(DocSection *) 
{
}

void LatexDocVisitor::visitPre(DocHtmlList *s)
{
814
  if (m_hide) return;
815
  if (s->type()==DocHtmlList::Ordered) 
816
    m_t << "\n\\begin{DoxyEnumerate}";
817
  else 
818
    m_t << "\n\\begin{DoxyItemize}";
819 820 821 822
}

void LatexDocVisitor::visitPost(DocHtmlList *s) 
{
823
  if (m_hide) return;
824
  if (s->type()==DocHtmlList::Ordered) 
825
    m_t << "\n\\end{DoxyEnumerate}";
826
  else 
827
    m_t << "\n\\end{DoxyItemize}";
828 829 830 831
}

void LatexDocVisitor::visitPre(DocHtmlListItem *)
{
832
  if (m_hide) return;
833
  m_t << "\n\\item ";
834 835 836 837 838 839
}

void LatexDocVisitor::visitPost(DocHtmlListItem *) 
{
}

840 841 842 843 844
//void LatexDocVisitor::visitPre(DocHtmlPre *)
//{
//  m_t << "\\small\\begin{alltt}";
//  m_insidePre=TRUE;
//}
845

846 847 848 849 850
//void LatexDocVisitor::visitPost(DocHtmlPre *) 
//{
//  m_insidePre=FALSE;
//  m_t << "\\end{alltt}\\normalsize " << endl;
//}
851

852
void LatexDocVisitor::visitPre(DocHtmlDescList *dl)
853
{
854
  if (m_hide) return;
855 856 857 858 859 860 861 862 863
  QCString val = dl->attribs().find("class");
  if (val=="reflist")
  {
    m_t << "\n\\begin{DoxyRefList}";
  }
  else
  {
    m_t << "\n\\begin{DoxyDescription}";
  }
864 865
}

866
void LatexDocVisitor::visitPost(DocHtmlDescList *dl) 
867
{
868
  if (m_hide) return;
869 870 871 872 873 874 875 876 877
  QCString val = dl->attribs().find("class");
  if (val=="reflist")
  {
    m_t << "\n\\end{DoxyRefList}";
  }
  else
  {
    m_t << "\n\\end{DoxyDescription}";
  }
878 879 880 881
}

void LatexDocVisitor::visitPre(DocHtmlDescTitle *)
{
882
  if (m_hide) return;
883
  m_t << "\n\\item[";
884
  m_insideItem=TRUE;
885 886 887 888
}

void LatexDocVisitor::visitPost(DocHtmlDescTitle *) 
{
889
  if (m_hide) return;
890
  m_insideItem=FALSE;
891 892 893 894 895 896 897 898 899 900 901 902 903
  m_t << "]";
}

void LatexDocVisitor::visitPre(DocHtmlDescData *)
{
}

void LatexDocVisitor::visitPost(DocHtmlDescData *) 
{
}

void LatexDocVisitor::visitPre(DocHtmlTable *t)
{
Dimitri van Heesch's avatar
Dimitri van Heesch committed
904 905
  m_rowSpans.clear();
  m_insideTable=TRUE;
906
  if (m_hide) return;
907 908 909 910
  if (t->hasCaption()) 
  {
    m_t << "\\begin{table}[h]";
  }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
911 912 913
  m_t << "\\begin{TabularC}{" << t->numColumns() << "}\n";
  m_numCols = t->numColumns();
  m_t << "\\hline\n";
914 915 916 917
}

void LatexDocVisitor::visitPost(DocHtmlTable *t) 
{
Dimitri van Heesch's avatar
Dimitri van Heesch committed
918
  m_insideTable=FALSE;
919
  if (m_hide) return;
920 921 922 923 924 925
  if (t->hasCaption())
  {
    m_t << "\\end{table}\n";
  }
  else
  {
926
    m_t << "\\end{TabularC}\n";
927 928 929 930 931
  }
}

void LatexDocVisitor::visitPre(DocHtmlCaption *)
{
932
  if (m_hide) return;
933
  m_t << "\\end{TabularC}\n\\centering\n\\caption{";
934 935 936 937
}

void LatexDocVisitor::visitPost(DocHtmlCaption *) 
{
938
  if (m_hide) return;
939 940 941
  m_t << "}\n";
}

942
void LatexDocVisitor::visitPre(DocHtmlRow *r)
943
{
944
  m_currentColumn = 0;
945
  if (r->isHeading()) m_t << "\\rowcolor{lightgray}";
946 947
}

Dimitri van Heesch's avatar
Dimitri van Heesch committed
948
void LatexDocVisitor::visitPost(DocHtmlRow *row) 
949
{
950
  if (m_hide) return;
951

Dimitri van Heesch's avatar
Dimitri van Heesch committed
952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982
  int c=m_currentColumn;
  while (c<=m_numCols) // end of row while inside a row span?
  {
    uint i;
    for (i=0;i<m_rowSpans.count();i++)
    {
      ActiveRowSpan *span = m_rowSpans.at(i);
      //printf("  founc row span: column=%d rs=%d cs=%d rowIdx=%d cell->rowIdx=%d\n",
      //    span->column, span->rowSpan,span->colSpan,row->rowIndex(),span->cell->rowIndex());
      if (span->rowSpan>0 && span->column==c &&  // we are at a cell in a row span
          row->rowIndex()>span->cell->rowIndex() // but not the row that started the span
         )
      {
        m_t << "&";
        if (span->colSpan>1) // row span is also part of a column span
        {
          m_t << "\\multicolumn{" << span->colSpan << "}{";
          m_t << "p{(\\linewidth-\\tabcolsep*" 
            << m_numCols << "-\\arrayrulewidth*"
            << row->visibleCells() << ")*" 
            << span->colSpan <<"/"<< m_numCols << "}|}{}";
        }
        else // solitary row span
        {
          m_t << "\\multicolumn{1}{c|}{}";
        }
      }
    }
    c++;
  }

983 984 985
  m_t << "\\\\";
  
  int col = 1;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
986 987
  uint i;
  for (i=0;i<m_rowSpans.count();i++)
988
  {
Dimitri van Heesch's avatar
Dimitri van Heesch committed
989 990 991 992 993 994 995
    ActiveRowSpan *span = m_rowSpans.at(i);
    if (span->rowSpan>0) span->rowSpan--;
    if (span->rowSpan<=0)
    {
      // inactive span
    }
    else if (span->column>col)
996
    {
Dimitri van Heesch's avatar
Dimitri van Heesch committed
997 998
      m_t << "\\cline{" << col << "-" << (span->column-1) << "}";
      col = span->column+span->colSpan;
999
    }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1000
    else
1001
    {
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1002
      col = span->column+span->colSpan;
1003
    }
1004
  }
1005

Dimitri van Heesch's avatar
Dimitri van Heesch committed
1006
  if (col <= m_numCols)
1007
  {
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1008
    m_t << "\\cline{" << col << "-" << m_numCols << "}";
1009
  }
1010 1011

  m_t << "\n";
1012 1013
}

1014
void LatexDocVisitor::visitPre(DocHtmlCell *c)
1015
{
1016
  if (m_hide) return;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1017 1018 1019 1020 1021 1022

  DocHtmlRow *row = 0;
  if (c->parent() && c->parent()->kind()==DocNode::Kind_HtmlRow)
  {
    row = (DocHtmlRow*)c->parent();
  }
1023 1024
  
  m_currentColumn++;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1025

1026
  //Skip columns that span from above.
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054
  uint i;
  for (i=0;i<m_rowSpans.count();i++)
  {
    ActiveRowSpan *span = m_rowSpans.at(i);
    if (span->rowSpan>0 && span->column==m_currentColumn)
    {
      if (row && span->colSpan>1)
      {
        m_t << "\\multicolumn{" << span->colSpan << "}{";
        if (m_currentColumn /*c->columnIndex()*/==1) // add extra | for first column
        {
          m_t << "|";
        }
        m_t << "p{(\\linewidth-\\tabcolsep*" 
            << m_numCols << "-\\arrayrulewidth*"
            << row->visibleCells() << ")*" 
            << span->colSpan <<"/"<< m_numCols << "}|}{}";
        m_currentColumn+=span->colSpan;
      }
      else
      {
        m_currentColumn++;
      }
      m_t << "&";
    }
  }

#if 0
1055
  QMap<int, int>::Iterator it = m_rowspanIndices.find(m_currentColumn);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1056
  if (it!=m_rowspanIndices.end() && it.data()>0)
1057 1058 1059 1060 1061
  {
    m_t << "&";
    m_currentColumn++;
    it++;
  }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1062
#endif
1063

Dimitri van Heesch's avatar
Dimitri van Heesch committed
1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079
  int cs = c->colSpan();
  if (cs>1 && row)
  {
    m_inColspan = TRUE;
    m_t << "\\multicolumn{" << cs << "}{";
    if (c->columnIndex()==1) // add extra | for first column
    {
      m_t << "|";
    }
    m_t << "p{(\\linewidth-\\tabcolsep*" 
        << m_numCols << "-\\arrayrulewidth*"
        << row->visibleCells() << ")*" 
        << cs <<"/"<< m_numCols << "}|}{";
    if (c->isHeading()) m_t << "\\cellcolor{lightgray}";
  }
  int rs = c->rowSpan();
1080
  if (rs>0)
1081 1082
  {
    m_inRowspan = TRUE;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1083 1084
    //m_rowspanIndices[m_currentColumn] = rs;
    m_rowSpans.append(new ActiveRowSpan(c,rs,cs,m_currentColumn));
1085 1086
    m_t << "\\multirow{" << rs << "}{\\linewidth}{";
  }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1087 1088
  int a = c->alignment();
  if (a==DocHtmlCell::Center)
1089 1090 1091
  {
    m_t << "\\PBS\\centering ";
  }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1092
  else if (a==DocHtmlCell::Right)
1093 1094 1095 1096 1097 1098 1099
  {
    m_t << "\\PBS\\raggedleft ";
  }
  if (c->isHeading())
  {
    m_t << "{\\bf ";
  }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1100 1101 1102 1103
  if (cs>1)
  {
    m_currentColumn+=cs-1;
  }
1104 1105 1106 1107
}

void LatexDocVisitor::visitPost(DocHtmlCell *c) 
{
1108
  if (m_hide) return;
1109 1110 1111 1112
  if (c->isHeading())
  {
    m_t << "}";
  }
1113 1114 1115 1116 1117
  if (m_inRowspan)
  {
    m_inRowspan = FALSE;
    m_t << "}";
  }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1118 1119 1120 1121 1122
  if (m_inColspan)
  {
    m_inColspan = FALSE;
    m_t << "}";
  }
1123 1124 1125 1126 1127
  if (!c->isLast()) m_t << "&";
}

void LatexDocVisitor::visitPre(DocInternal *)
{
1128
  if (m_hide) return;
1129 1130 1131
  //m_t << "\\begin{DoxyInternal}{";
  //filter(theTranslator->trForInternalUseOnly());
  //m_t << "}\n";
1132 1133 1134 1135
}

void LatexDocVisitor::visitPost(DocInternal *) 
{
1136
  if (m_hide) return;
1137
  //m_t << "\\end{DoxyInternal}" << endl;
1138 1139 1140 1141
}

void LatexDocVisitor::visitPre(DocHRef *href)
{
1142
  if (m_hide) return;
1143 1144 1145 1146 1147 1148
  if (Config_getBool("PDF_HYPERLINKS"))
  {
    m_t << "\\href{";
    m_t << href->url();
    m_t << "}";
  }
1149
  m_t << "{\\tt ";
1150 1151 1152 1153
}

void LatexDocVisitor::visitPost(DocHRef *) 
{
1154
  if (m_hide) return;
1155 1156 1157 1158 1159
  m_t << "}";
}

void LatexDocVisitor::visitPre(DocHtmlHeader *header)
{
1160
  if (m_hide) return;
1161
  m_t << "\\" << getSectionName(header->level()) << "*{";
1162 1163 1164 1165
}

void LatexDocVisitor::visitPost(DocHtmlHeader *) 
{
1166
  if (m_hide) return;
1167 1168 1169 1170 1171 1172 1173
  m_t << "}";
}

void LatexDocVisitor::visitPre(DocImage *img)
{
  if (img->type()==DocImage::Latex)
  {
1174
    if (m_hide) return;
1175 1176
    if (img->hasCaption())
    {
1177
      m_t << "\n\\begin{DoxyImage}\n";
1178 1179 1180
    }
    else
    {
1181 1182
      m_t << "\n\\begin{DoxyImageNoCaption}\n"
             "  \\mbox{";
1183
    }
1184
    QCString gfxName = img->name();
1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200
    if (gfxName.right(4)==".eps" || gfxName.right(4)==".pdf")
    {
      gfxName=gfxName.left(gfxName.length()-4);
    }
    m_t << "\\includegraphics";
    if (!img->width().isEmpty())
    {
      m_t << "[width=" << img->width() << "]";
    }
    else if (!img->height().isEmpty())
    {
      m_t << "[height=" << img->height() << "]";
    }
    m_t << "{" << gfxName << "}";
    if (img->hasCaption())
    {
1201
      m_t << "\n\\caption{";
1202 1203 1204 1205
    }
  }
  else // other format -> skip
  {
1206
    pushEnabled();
1207 1208 1209 1210 1211 1212 1213 1214
    m_hide=TRUE;
  }
}

void LatexDocVisitor::visitPost(DocImage *img) 
{
  if (img->type()==DocImage::Latex)
  {
1215
    if (m_hide) return;
1216
    m_t << "}\n"; // end mbox or caption
1217 1218
    if (img->hasCaption())
    {
1219
      m_t << "\\end{DoxyImage}\n";
1220 1221
    }
    else{
1222
      m_t << "\\end{DoxyImageNoCaption}\n";
1223 1224 1225 1226
    }
  }
  else // other format
  {
1227
    popEnabled();
1228 1229 1230 1231 1232
  }
}

void LatexDocVisitor::visitPre(DocDotFile *df)
{
1233
  if (m_hide) return;
1234
  startDotFile(df->file(),df->width(),df->height(),df->hasCaption());
1235 1236 1237 1238
}

void LatexDocVisitor::visitPost(DocDotFile *df) 
{
1239
  if (m_hide) return;
1240
  endDotFile(df->hasCaption());
1241
}
1242 1243 1244 1245 1246
void LatexDocVisitor::visitPre(DocMscFile *df)
{
  if (m_hide) return;
  startMscFile(df->file(),df->width(),df->height(),df->hasCaption());
}
1247

1248 1249 1250 1251 1252
void LatexDocVisitor::visitPost(DocMscFile *df) 
{
  if (m_hide) return;
  endMscFile(df->hasCaption());
}
1253 1254
void LatexDocVisitor::visitPre(DocLink *lnk)
{
1255
  if (m_hide) return;
1256 1257 1258
  startLink(lnk->ref(),lnk->file(),lnk->anchor());
}

Dimitri van Heesch's avatar
Dimitri van Heesch committed
1259
void LatexDocVisitor::visitPost(DocLink *lnk) 
1260
{
1261
  if (m_hide) return;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1262
  endLink(lnk->ref(),lnk->file(),lnk->anchor());
1263 1264 1265 1266
}

void LatexDocVisitor::visitPre(DocRef *ref)
{
1267
  if (m_hide) return;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1268 1269 1270 1271 1272 1273 1274 1275 1276 1277
  // when ref->isSubPage()==TRUE we use ref->file() for HTML and
  // ref->anchor() for LaTeX/RTF
  if (ref->isSubPage())
  {
    startLink(ref->ref(),0,ref->anchor());
  }
  else
  {
    if (!ref->file().isEmpty()) startLink(ref->ref(),ref->file(),ref->anchor());
  }
1278 1279 1280
  if (!ref->hasLinkText()) filter(ref->targetTitle());
}

Dimitri van Heesch's avatar
Dimitri van Heesch committed
1281
void LatexDocVisitor::visitPost(DocRef *ref) 
1282
{
1283
  if (m_hide) return;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1284 1285 1286 1287 1288 1289 1290 1291
  if (ref->isSubPage())
  {
    endLink(ref->ref(),0,ref->anchor());
  }
  else
  {
    if (!ref->file().isEmpty()) endLink(ref->ref(),ref->file(),ref->anchor());
  }
1292 1293 1294 1295
}

void LatexDocVisitor::visitPre(DocSecRefItem *)
{
1296
  if (m_hide) return;
1297 1298 1299 1300 1301
  m_t << "\\item \\contentsline{section}{";
}

void LatexDocVisitor::visitPost(DocSecRefItem *ref) 
{
1302
  if (m_hide) return;
1303
  m_t << "}{\\ref{" << ref->file() << "_" << ref->anchor() << "}}{}" << endl;
1304 1305 1306 1307
}

void LatexDocVisitor::visitPre(DocSecRefList *)
{
1308
  if (m_hide) return;
1309 1310
  m_t << "\\footnotesize" << endl;
  m_t << "\\begin{multicols}{2}" << endl;
1311
  m_t << "\\begin{DoxyCompactList}" << endl;
1312 1313 1314 1315
}

void LatexDocVisitor::visitPost(DocSecRefList *) 
{
1316
  if (m_hide) return;
1317
  m_t << "\\end{DoxyCompactList}" << endl;
1318 1319 1320 1321 1322 1323
  m_t << "\\end{multicols}" << endl;
  m_t << "\\normalsize" << endl;
}

void LatexDocVisitor::visitPre(DocParamSect *s)
{
1324
  if (m_hide) return;
1325 1326
  bool hasInOutSpecs = s->hasInOutSpecifier();
  bool hasTypeSpecs  = s->hasTypeSpecifier();
1327 1328
  switch(s->type())
  {
1329
    case DocParamSect::Param:
1330 1331 1332 1333
      m_t << "\n\\begin{DoxyParams}";
      if      (hasInOutSpecs && hasTypeSpecs) m_t << "[2]"; // 2 extra cols
      else if (hasInOutSpecs || hasTypeSpecs) m_t << "[1]"; // 1 extra col
      m_t << "{";
1334 1335 1336 1337 1338 1339
      filter(theTranslator->trParameters());
      break;
    case DocParamSect::RetVal:
      m_t << "\n\\begin{DoxyRetVals}{";
      filter(theTranslator->trReturnValues());
      break;
1340
    case DocParamSect::Exception: 
1341 1342 1343
      m_t << "\n\\begin{DoxyExceptions}{";
      filter(theTranslator->trExceptions());
      break;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1344 1345 1346 1347
    case DocParamSect::TemplateParam: 
      /* TODO: add this 
      filter(theTranslator->trTemplateParam()); break;
      */
1348 1349 1350
      m_t << "\n\\begin{DoxyTemplParams}{";
      filter("Template Parameters");
      break;
1351 1352 1353
    default:
      ASSERT(0);
  }
1354
  m_t << "}\n";
1355 1356
}

1357
void LatexDocVisitor::visitPost(DocParamSect *s)
1358
{
1359
  if (m_hide) return;
1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376
  switch(s->type())
  {
    case DocParamSect::Param:
      m_t << "\\end{DoxyParams}\n";
      break;
    case DocParamSect::RetVal:
      m_t << "\\end{DoxyRetVals}\n";
      break;
    case DocParamSect::Exception: 
      m_t << "\\end{DoxyExceptions}\n";
      break;
    case DocParamSect::TemplateParam: 
      m_t << "\\end{DoxyTemplParams}\n";
      break;
    default:
      ASSERT(0);
  }
1377 1378 1379 1380
}

void LatexDocVisitor::visitPre(DocParamList *pl)
{
1381
  if (m_hide) return;
1382 1383 1384
  DocParamSect::Type parentType = DocParamSect::Unknown;
  DocParamSect *sect = 0;
  if (pl->parent() && pl->parent()->kind()==DocNode::Kind_ParamSect)
1385
  {
1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399
    parentType = ((DocParamSect*)pl->parent())->type();
    sect=(DocParamSect*)pl->parent();
  }
  bool useTable = parentType==DocParamSect::Param ||
                  parentType==DocParamSect::RetVal ||
                  parentType==DocParamSect::Exception ||
                  parentType==DocParamSect::TemplateParam;
  if (!useTable)
  {
    m_t << "\\item[";
  }
  if (sect && sect->hasInOutSpecifier())
  {
    if (pl->direction()!=DocParamSect::Unspecified)
1400
    {
1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414
      m_t << "\\mbox{\\tt ";
      if (pl->direction()==DocParamSect::In)
      {
        m_t << "in";
      }
      else if (pl->direction()==DocParamSect::Out)
      {
        m_t << "out";
      }
      else if (pl->direction()==DocParamSect::InOut)
      {
        m_t << "in,out";
      }
      m_t << "} ";
1415
    }
1416 1417 1418 1419 1420 1421 1422 1423
    if (useTable) m_t << " & ";
  }
  if (sect && sect->hasTypeSpecifier())
  {
    QListIterator<DocNode> li(pl->paramTypes());
    DocNode *type;
    bool first=TRUE;
    for (li.toFirst();(type=li.current());++li)
1424
    {
1425 1426 1427 1428 1429 1430 1431 1432 1433
      if (!first) m_t << " | "; else first=FALSE;
      if (type->kind()==DocNode::Kind_Word)
      {
        visit((DocWord*)type); 
      }
      else if (type->kind()==DocNode::Kind_LinkedWord)
      {
        visit((DocLinkedWord*)type); 
      }
1434
    }
1435
    if (useTable) m_t << " & ";
1436 1437
  }
  m_t << "{\\em ";
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1438 1439 1440 1441
  //QStrListIterator li(pl->parameters());
  //const char *s;
  QListIterator<DocNode> li(pl->parameters());
  DocNode *param;
1442
  bool first=TRUE;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1443
  for (li.toFirst();(param=li.current());++li)
1444 1445
  {
    if (!first) m_t << ","; else first=FALSE;
1446
    m_insideItem=TRUE;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1447 1448 1449 1450 1451 1452 1453 1454
    if (param->kind()==DocNode::Kind_Word)
    {
      visit((DocWord*)param); 
    }
    else if (param->kind()==DocNode::Kind_LinkedWord)
    {
      visit((DocLinkedWord*)param); 
    }
1455
    m_insideItem=FALSE;
1456
  }
1457 1458 1459 1460 1461 1462 1463 1464 1465
  m_t << "}";
  if (useTable)
  {
    m_t << " & ";
  }
  else
  {
    m_t << "]";
  }
1466 1467
}

1468
void LatexDocVisitor::visitPost(DocParamList *pl)
1469
{
1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484
  if (m_hide) return;
  DocParamSect::Type parentType = DocParamSect::Unknown;
  if (pl->parent() && pl->parent()->kind()==DocNode::Kind_ParamSect)
  {
    parentType = ((DocParamSect*)pl->parent())->type();
  }
  bool useTable = parentType==DocParamSect::Param ||
                  parentType==DocParamSect::RetVal ||
                  parentType==DocParamSect::Exception ||
                  parentType==DocParamSect::TemplateParam;
  if (useTable)
  {
    m_t << "\\\\" << endl
        << "\\hline" << endl;
  }
1485 1486 1487 1488
}

void LatexDocVisitor::visitPre(DocXRefItem *x)
{
1489
  if (m_hide) return;
1490 1491 1492
  m_t << "\\begin{DoxyRefDesc}{";
  filter(x->title());
  m_t << "}" << endl;
1493
  bool anonymousEnum = x->file()=="@";
1494
  m_t << "\\item[";
1495
  if (Config_getBool("PDF_HYPERLINKS") && !anonymousEnum)
1496
  {
1497
    m_t << "\\hyperlink{" << stripPath(x->file()) << "_" << x->anchor() << "}{";
1498 1499 1500
  }
  else
  {
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1501
    m_t << "{\\bf ";
1502
  }
1503
  m_insideItem=TRUE;
1504
  filter(x->title());
1505
  m_insideItem=FALSE;
1506 1507 1508 1509 1510
  m_t << "}]";
}

void LatexDocVisitor::visitPost(DocXRefItem *)
{
1511
  if (m_hide) return;
1512
  m_t << "\\end{DoxyRefDesc}" << endl;
1513 1514 1515 1516
}

void LatexDocVisitor::visitPre(DocInternalRef *ref)
{
1517
  if (m_hide) return;
1518 1519 1520
  startLink(0,ref->file(),ref->anchor());
}

Dimitri van Heesch's avatar
Dimitri van Heesch committed
1521
void LatexDocVisitor::visitPost(DocInternalRef *ref) 
1522
{
1523
  if (m_hide) return;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1524
  endLink(0,ref->file(),ref->anchor());
1525 1526 1527 1528 1529 1530 1531 1532 1533 1534
}

void LatexDocVisitor::visitPre(DocCopy *)
{
}

void LatexDocVisitor::visitPost(DocCopy *)
{
}

Dimitri van Heesch's avatar
Dimitri van Heesch committed
1535
void LatexDocVisitor::visitPre(DocText *)
1536 1537 1538 1539 1540 1541 1542
{
}

void LatexDocVisitor::visitPost(DocText *)
{
}

1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554
void LatexDocVisitor::visitPre(DocHtmlBlockQuote *)
{
  if (m_hide) return;
  m_t << "\\begin{quotation}" << endl;
}

void LatexDocVisitor::visitPost(DocHtmlBlockQuote *)
{
  if (m_hide) return;
  m_t << "\\end{quotation}" << endl;
}

1555 1556 1557 1558 1559 1560 1561 1562 1563 1564
void LatexDocVisitor::visitPre(DocVhdlFlow *)
{
  if (m_hide) return;
}

void LatexDocVisitor::visitPost(DocVhdlFlow *)
{
  if (m_hide) return;
}

Dimitri van Heesch's avatar
Dimitri van Heesch committed
1565
void LatexDocVisitor::filter(const char *str)
1566
{ 
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1567
  filterLatexString(m_t,str,m_insideTabbing,m_insidePre,m_insideItem);
1568 1569
}

1570
void LatexDocVisitor::startLink(const QCString &ref,const QCString &file,const QCString &anchor)
1571
{
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1572
  if (ref.isEmpty() && Config_getBool("PDF_HYPERLINKS")) // internal PDF link 
1573
  {
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589
    if (ref.isEmpty()) {
      m_t << "\\hyperlink{";
      if (!file.isEmpty()) m_t << stripPath(file);
      if (!file.isEmpty() && !anchor.isEmpty()) m_t << "_";
      if (!anchor.isEmpty()) m_t << anchor;
      m_t << "}{";
    }
    else
    {
      QCString *dest;
      m_t << "\\href{";
      if ((dest=Doxygen::tagDestinationDict[ref])) m_t << *dest << "/";
      if (!file.isEmpty()) m_t << file << Doxygen::htmlFileExtension;
      if (!anchor.isEmpty()) m_t << "#" << anchor;
      m_t << "}{";
    }
1590
  }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1591
  else if (ref.isEmpty()) // internal non-PDF link
1592
  {
1593
    m_t << "\\doxyref{";
1594
  }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1595 1596 1597 1598
  else // external link
  { 
    m_t << "{\\bf ";
  }
1599 1600
}

1601
void LatexDocVisitor::endLink(const QCString &ref,const QCString &file,const QCString &anchor)
1602 1603
{
  m_t << "}";
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1604 1605
  if (ref.isEmpty() && !Config_getBool("PDF_HYPERLINKS"))
  {
1606
    m_t << "{"; 
1607
    filter(theTranslator->trPageAbbreviation());
1608
    m_t << "}{" << file;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1609
    if (!anchor.isEmpty()) m_t << "_" << anchor;
1610
    m_t << "}";
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1611
  }
1612 1613
}

1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626
void LatexDocVisitor::pushEnabled()
{
  m_enabled.push(new bool(m_hide));
}

void LatexDocVisitor::popEnabled()
{
  bool *v=m_enabled.pop();
  ASSERT(v!=0);
  m_hide = *v;
  delete v;
}

1627 1628 1629
void LatexDocVisitor::startDotFile(const QCString &fileName,
                                   const QCString &width,
                                   const QCString &height,
1630 1631 1632
                                   bool hasCaption
                                  )
{
1633
  QCString baseName=fileName;
1634 1635 1636 1637 1638
  int i;
  if ((i=baseName.findRev('/'))!=-1)
  {
    baseName=baseName.right(baseName.length()-i-1);
  } 
1639
  if ((i=baseName.find('.'))!=-1)
1640
  {
1641
    baseName=baseName.left(i);
1642
  }
1643
  baseName.prepend("dot_");
1644 1645
  QCString outDir = Config_getString("LATEX_OUTPUT");
  QCString name = fileName;
1646 1647 1648
  writeDotGraphFromFile(name,outDir,baseName,EPS);
  if (hasCaption)
  {
1649
    m_t << "\n\\begin{DoxyImage}\n";
1650 1651 1652
  }
  else
  {
1653 1654
    m_t << "\n\\begin{DoxyImageNoCaption}\n"
           "  \\mbox{";
1655 1656 1657 1658 1659 1660 1661 1662 1663 1664
  }
  m_t << "\\includegraphics";
  if (!width.isEmpty())
  {
    m_t << "[width=" << width << "]";
  }
  else if (!height.isEmpty())
  {
    m_t << "[height=" << height << "]";
  }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1665 1666
  else
  {
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1667
    m_t << "[width=\\textwidth,height=\\textheight/2,keepaspectratio=true]";
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1668
  }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1669 1670 1671 1672 1673 1674 1675 1676 1677 1678
  m_t << "{" << baseName;
  //if (Config_getBool("USE_PDFLATEX"))
  //{
  //  m_t << ".pdf";
  //}
  //else
  //{
  //  m_t << ".eps";
  //}
  m_t << "}";
1679 1680 1681

  if (hasCaption)
  {
1682
    m_t << "\n\\caption{";
1683 1684 1685 1686 1687 1688
  }
}

void LatexDocVisitor::endDotFile(bool hasCaption)
{
  if (m_hide) return;
1689
  m_t << "}\n"; // end caption or mbox
1690 1691
  if (hasCaption)
  {
1692
    m_t << "\\end{DoxyImage}\n";
1693 1694 1695
  }
  else
  {
1696
    m_t << "\\end{DoxyImageNoCaption}\n";
1697 1698 1699
  }
}

1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711
void LatexDocVisitor::startMscFile(const QCString &fileName,
                                   const QCString &width,
                                   const QCString &height,
                                   bool hasCaption
                                  )
{
  QCString baseName=fileName;
  int i;
  if ((i=baseName.findRev('/'))!=-1)
  {
    baseName=baseName.right(baseName.length()-i-1);
  } 
1712
  if ((i=baseName.find('.'))!=-1)
1713
  {
1714
    baseName=baseName.left(i);
1715
  }
1716 1717
  baseName.prepend("msc_");

1718
  QCString outDir = Config_getString("LATEX_OUTPUT");
1719
  writeMscGraphFromFile(fileName,outDir,baseName,MSC_EPS); 
1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737
  if (hasCaption)
  {
    m_t << "\n\\begin{DoxyImage}\n";
  }
  else
  {
    m_t << "\n\\begin{DoxyImageNoCaption}\n"
           "  \\mbox{";
  }
  m_t << "\\includegraphics";
  if (!width.isEmpty())
  {
    m_t << "[width=" << width << "]";
  }
  else if (!height.isEmpty())
  {
    m_t << "[height=" << height << "]";
  }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1738 1739
  else
  {
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1740
    m_t << "[width=\\textwidth,height=\\textheight/2,keepaspectratio=true]";
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1741
  }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1742 1743 1744 1745 1746 1747 1748 1749 1750 1751
  m_t << "{" << baseName;
  //if (Config_getBool("USE_PDFLATEX"))
  //{
  //  m_t << ".pdf";
  //}
  //else
  //{
  //  m_t << ".eps";
  //}
  m_t << "}";
1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773

  if (hasCaption)
  {
    m_t << "\n\\caption{";
  }
}

void LatexDocVisitor::endMscFile(bool hasCaption)
{
  if (m_hide) return;
  m_t << "}\n"; // end caption or mbox
  if (hasCaption)
  {
    m_t << "\\end{DoxyImage}\n";
  }
  else
  {
    m_t << "\\end{DoxyImageNoCaption}\n";
  }
}


1774
void LatexDocVisitor::writeMscFile(const QCString &baseName)
1775
{
1776
  QCString shortName = baseName;
1777 1778 1779 1780 1781
  int i;
  if ((i=shortName.findRev('/'))!=-1)
  {
    shortName=shortName.right(shortName.length()-i-1);
  } 
1782
  QCString outDir = Config_getString("LATEX_OUTPUT");
1783
  writeMscGraphFromFile(baseName+".msc",outDir,shortName,MSC_EPS);
1784 1785
  m_t << "\n\\begin{DoxyImageNoCaption}"
         "  \\mbox{\\includegraphics";
1786
  m_t << "{" << shortName << "}";
1787 1788
  m_t << "}\n"; // end mbox
  m_t << "\\end{DoxyImageNoCaption}\n";
1789 1790
}