|
| 1 | +# LatexGenC++ |
| 2 | + |
| 3 | +A C++ library for programmatically generating LaTeX documents. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +LatexGenC++ is a comprehensive C++ library that allows programmatic generation of LaTeX documents. It provides an object-oriented API for creating various types of LaTeX documents, including articles, reports, books, and presentations, with support for multilingual content. |
| 8 | + |
| 9 | +## Features |
| 10 | + |
| 11 | +- **Multiple Document Types**: Support for articles, reports, books, and Beamer presentations |
| 12 | +- **Structured Content**: Easy management of sections, subsections, chapters, parts, etc. |
| 13 | +- **Rich Elements**: Figures, tables, equations, lists, theorems, algorithms |
| 14 | +- **Bibliography Management**: Two methods for handling bibliographies: |
| 15 | + - Using external .bib files |
| 16 | + - Creating references programmatically |
| 17 | +- **Multilingual Support**: 11 languages including English, French, German, Spanish, etc. |
| 18 | +- **Custom Templates**: Apply consistent styling across documents |
| 19 | +- **Index Generation**: Support for creating document indexes |
| 20 | + |
| 21 | +## Installation |
| 22 | + |
| 23 | +### Prerequisites |
| 24 | + |
| 25 | +- C++ compiler with C++17 support |
| 26 | +- CMake (version 3.10 or higher) |
| 27 | + |
| 28 | +### Build and Install |
| 29 | + |
| 30 | +```bash |
| 31 | +# Clone the repository |
| 32 | +git clone https://github.com/yourusername/LatexGenCpp.git |
| 33 | + |
| 34 | +# Create a build directory |
| 35 | +cd LatexGenCpp |
| 36 | +mkdir build && cd build |
| 37 | + |
| 38 | +# Configure and build |
| 39 | +cmake .. |
| 40 | +make |
| 41 | + |
| 42 | +# Install (optional) |
| 43 | +sudo make install |
| 44 | +``` |
| 45 | + |
| 46 | +## Usage Examples |
| 47 | + |
| 48 | +A detailed documentation is available in the `doc/` directory. Below are some basic usage examples to get you started. (hers is the link to the documentation: [FR](doc/DOCUMENTATION_FR.md), [EN](doc/DOCUMENTATION_EN.md)) |
| 49 | + |
| 50 | +### Creating a Simple Article |
| 51 | + |
| 52 | +```cpp |
| 53 | +#include "latexgen.h" |
| 54 | +#include <iostream> |
| 55 | + |
| 56 | +using namespace LatexGen; |
| 57 | + |
| 58 | +int main() { |
| 59 | + // Create an article |
| 60 | + Article article("My Document Title", "Author Name", "Today"); |
| 61 | + |
| 62 | + // Add a section |
| 63 | + Section section("Introduction", Section::Level::SECTION); |
| 64 | + section.addContent("This is the content of my first section."); |
| 65 | + |
| 66 | + // Add the section to the article |
| 67 | + article.addSection(section); |
| 68 | + |
| 69 | + // Save the document |
| 70 | + if (article.saveToFile("output", "mydocument.tex")) { |
| 71 | + std::cout << "Document created successfully!" << std::endl; |
| 72 | + } |
| 73 | + |
| 74 | + return 0; |
| 75 | +} |
| 76 | +``` |
| 77 | + |
| 78 | +### Adding Figures and Tables |
| 79 | + |
| 80 | +```cpp |
| 81 | +// Adding a figure |
| 82 | +auto figure = document.addFigure( |
| 83 | + "image.png", // Image path |
| 84 | + "Figure Caption", // Caption |
| 85 | + "fig:label", // Label for reference |
| 86 | + "0.7\\textwidth", // Width |
| 87 | + "htbp" // Position |
| 88 | +); |
| 89 | + |
| 90 | +// Adding a table |
| 91 | +std::vector<std::string> headers = {"Column 1", "Column 2", "Column 3"}; |
| 92 | +auto table = document.addTable( |
| 93 | + headers, // Column headers |
| 94 | + "Table Caption", // Caption |
| 95 | + "tab:label", // Label for reference |
| 96 | + "htbp" // Position |
| 97 | +); |
| 98 | + |
| 99 | +// Adding rows to the table |
| 100 | +table->addRow({"Value 1", "Value 2", "Value 3"}); |
| 101 | +table->addRow({"Value 4", "Value 5", "Value 6"}); |
| 102 | +``` |
| 103 | +
|
| 104 | +### Using Bibliographies |
| 105 | +
|
| 106 | +```cpp |
| 107 | +// Method 1: Using an existing external .bib file |
| 108 | +Bibliography biblio("references", BibStyle::IEEE); |
| 109 | +document.setBibliography(biblio); |
| 110 | +
|
| 111 | +// Method 2: Creating references programmatically |
| 112 | +Bibliography biblio2; |
| 113 | +biblio2.setStyle(BibStyle::IEEE); |
| 114 | +
|
| 115 | +// Create an article entry |
| 116 | +BibEntry article("smith2023", BibEntry::EntryType::ARTICLE); |
| 117 | +article.addField("author", "John Smith"); |
| 118 | +article.addField("title", "Introduction to LaTeX Programming"); |
| 119 | +article.addField("journal", "Journal of Document Engineering"); |
| 120 | +article.addField("year", "2023"); |
| 121 | +article.addField("volume", "42"); |
| 122 | +article.addField("pages", "123--456"); |
| 123 | +
|
| 124 | +// Add the entry to the bibliography |
| 125 | +biblio2.addEntry(article); |
| 126 | +
|
| 127 | +// Generate the .bib file |
| 128 | +biblio2.generateBibFile("output"); |
| 129 | +
|
| 130 | +// Use the bibliography in the document |
| 131 | +document.setBibliography(biblio2); |
| 132 | +
|
| 133 | +// Cite a reference |
| 134 | +document.addRawContent("According to " + document.cite("smith2023") + ", the theory is valid."); |
| 135 | +``` |
| 136 | + |
| 137 | +## Documentation |
| 138 | + |
| 139 | +For a comprehensive guide to all features, see the examples in the `example/` directory: |
| 140 | + |
| 141 | +- `article_example.cpp`: Creating a scientific article |
| 142 | +- `book_example.cpp`: Creating a book with parts, chapters, and appendices |
| 143 | +- `report_example.cpp`: Creating a technical report |
| 144 | +- `presentation_example.cpp`: Creating a Beamer presentation |
| 145 | +- `index_example.cpp`: Using indexing features |
| 146 | +- `multilingual_example.cpp`: Creating documents in different languages |
| 147 | + |
| 148 | +## License |
| 149 | + |
| 150 | +This project is licensed under the GPL-3.0 License. See the [LICENSE](LICENSE) file for details. |
| 151 | + |
| 152 | +## Author |
| 153 | + |
| 154 | +Sofiane KHELLADI |
| 155 | + |
| 156 | +## Contributing |
| 157 | + |
| 158 | +Contributions are welcome! Please feel free to submit a Pull Request. |
0 commit comments