-
Notifications
You must be signed in to change notification settings - Fork 0
/
latex.cpp
75 lines (69 loc) · 1.77 KB
/
latex.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include "latex.h"
#include "utilities.h"
#include "solver.h"
#include <fstream>
void ScacchieraLaTeX(std::ofstream& f, Scacchiera& s)
{
f << "\n\\begin{sudoku}\n";
for (int y=1;y<=Y;++y)
{
for (int x=1;x<=X;++x)
f << "|" << (s.valore(x,y)==0?' ':s.valore(x,y));
f << "|.\n";
}
f << "\\end{sudoku}" << std::flush;
}
void ScacchieraLaTeX(std::ofstream& f, char* s)
{
f << "\n\\begin{sudoku}\n";
for (int y=0;y<Y;++y)
{
for (int x=0;x<X;++x)
f << "|" << (s[y*X+x]=='0'?' ':s[y*X+x]);
f << "|.\n";
}
f << "\\end{sudoku}" << std::flush;
}
void ScacchieraLaTeX(char* filename, char* s)
{
std::ofstream f;
f.open(filename);
ScacchieraLaTeX(f,s);
f.close();
}
void ScacchieraLaTeX(char* filename, Scacchiera& s)
{
std::ofstream f;
f.open(filename);
ScacchieraLaTeX(f,s);
f.close();
}
void FileLaTeX(char* filename, char* sudoku)
{
std::ofstream f;
f.open(filename);
f << "%Automatically generated by sudoku <[email protected]>";
f << "\n%Package sudoku.sty is required to renderize";
f << "\n\n\\documentclass{article}";
f << "\n\\usepackage{sudoku}";
f << "\n\\usepackage[utf-8]{inputenc}";
f << "\n\\title{Sudoku}";
f << "\n\n\\begin{document}\n";
f << "\n\\maketitle";
f << "\nAutomatic generated sudokus by sudoku\\\\";
int nsudoku = contasudoku(sudoku);
f << "\n Number of sudokus: " << nsudoku;
for (int n=0;n<nsudoku;++n)
{
f << "\n\\begin{figure}[htp]";
char *stringa = sudoku_n(sudoku, n);
ScacchieraLaTeX(f,stringa);
Solver a(stringa);
f << "\n\\caption{Sudoku number " << n+1 << ", difficulty " << a.difficolta() << "}";
f << "\n\\end{figure}\n";
f << "\n\\clearpage";
delete[] stringa;
}
f << "\n\\end{document}";
f.close();
}