Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
competitive
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Bruno Freitas Tissei
competitive
Commits
f1339082
Commit
f1339082
authored
6 years ago
by
Bruno Freitas Tissei
Browse files
Options
Downloads
Patches
Plain Diff
Fix a lot of stuff
Signed-off-by:
Bruno Freitas Tissei
<
bft15@inf.ufpr.br
>
parent
4b213008
No related branches found
No related tags found
No related merge requests found
Changes
24
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
gen_notebook
+11
-6
11 additions, 6 deletions
gen_notebook
misc/template.cpp
+1
-0
1 addition, 0 deletions
misc/template.cpp
notebook/gen_latex.py
+73
-38
73 additions, 38 deletions
notebook/gen_latex.py
notebook/header.tex
+1
-1
1 addition, 1 deletion
notebook/header.tex
with
86 additions
and
45 deletions
gen_notebook
+
11
−
6
View file @
f1339082
#!/bin/bash
#!/bin/bash
#tex_file=$(mktemp)
if
[
"
$1
"
=
"DEBUG"
]
;
then
python3 notebook/gen_latex.py
# --header=notebook/header.tex --output=$tex_file
tex_file
=
result.tex
python3 notebook/gen_latex.py
--header
=
notebook/header.tex
--output
=
$tex_file
else
tex_file
=
$(
mktemp
)
python3 notebook/gen_latex.py
--header
=
notebook/header.tex
--output
=
$tex_file
#
pdflatex $tex_file -output-directory . &&
pdflatex
$tex_file
-output-directory
.
&&
#
pdflatex $tex_file -output-directory .
pdflatex
$tex_file
-output-directory
.
#mv tmp.pdf caderno.pdf
mv
tmp.pdf caderno.pdf
#rm tmp*
rm
tmp
*
fi
This diff is collapsed.
Click to expand it.
misc/template.cpp
+
1
−
0
View file @
f1339082
/// Template
#include
<bits/stdc++.h>
#include
<bits/stdc++.h>
#define EPS 1e-6
#define EPS 1e-6
...
...
This diff is collapsed.
Click to expand it.
notebook/gen_latex.py
+
73
−
38
View file @
f1339082
import
argparse
from
pathlib
import
Path
from
pathlib
import
Path
class
Tree
:
class
Tree
:
# Constructor.
# @param dirs list of directories to build Latex over
def
__init__
(
self
,
dirs
):
def
__init__
(
self
,
dirs
):
self
.
dirs
=
dirs
;
self
.
dirs
=
dirs
;
self
.
tree
=
{}
self
.
tree
=
{}
self
.
build
()
self
.
build
()
# Sorts the lists on tree leaves.
def
sort
(
self
,
sub
):
if
type
(
sub
)
==
list
:
return
sorted
(
sub
)
else
:
for
i
in
sub
:
sub
[
i
]
=
self
.
sort
(
sub
[
i
])
return
sub
# Builds a tree represented as dict, with structure of files
# Builds a tree represented as dict, with structure of files
# and directories.
# and directories.
def
build
(
self
):
def
build
(
self
):
for
di
in
self
.
dirs
:
for
di
in
self
.
dirs
:
path_list
=
Path
(
di
).
glob
(
'
**/*.cpp
'
)
path_list
=
sorted
(
list
(
Path
(
di
).
glob
(
'
**/*.cpp
'
)
))
for
path
in
path_list
:
for
path
in
path_list
:
branch
=
str
(
path
).
split
(
'
/
'
)
branch
=
str
(
path
).
split
(
'
/
'
)
curr
=
self
.
tree
node
=
self
.
tree
for
i
in
branch
[:
-
2
]:
for
i
in
branch
[:
-
2
]:
if
not
i
in
curr
:
if
i
not
i
n
node
:
curr
[
i
]
=
{}
node
[
i
]
=
{}
curr
=
curr
[
i
]
node
=
node
[
i
]
if
not
branch
[
-
2
]
in
curr
:
if
branch
[
-
2
]
not
in
node
:
curr
[
branch
[
-
2
]]
=
[]
node
[
branch
[
-
2
]]
=
[]
curr
[
branch
[
-
2
]].
append
(
str
(
branch
[
-
1
]))
node
[
branch
[
-
2
]].
append
(
str
(
branch
[
-
1
]))
self
.
tree
=
self
.
sort
(
self
.
tree
)
# Allows access to tree dict from instance of class.
def
__getitem__
(
self
,
arg
):
def
__getitem__
(
self
,
arg
):
return
self
.
tree
[
arg
]
return
self
.
tree
[
arg
]
# Allows iteration on tree dict from instance of class.
def
__iter__
(
self
):
def
__iter__
(
self
):
return
iter
(
self
.
tree
)
return
iter
(
self
.
tree
)
class
LatexGenerator
:
class
LatexGenerator
:
def
__init__
(
self
,
tree
):
def
__init__
(
self
,
tree
,
output
,
header
):
# TODO: Create output file, add header and finish code parsing and latex
self
.
output
=
open
(
output
,
'
w
'
)
self
.
header
=
open
(
header
,
'
r
'
)
self
.
tree
=
tree
self
.
tree
=
tree
self
.
hierarchy
=
[
'
chapter
'
]
+
[
i
*
'
sub
'
+
'
section
'
for
i
in
range
(
3
)]
self
.
files
=
{}
self
.
hierarchy
=
[
'
part
'
,
'
chapter
'
]
+
[
i
*
'
sub
'
+
'
section
'
for
i
in
range
(
3
)]
self
.
_add_header
()
self
.
gen_latex
(
tree
)
self
.
gen_latex
(
tree
)
self
.
output
.
write
(
'
\end{document}
'
)
# Adds Latex header to the output.
def
_add_header
(
self
):
lines
=
self
.
header
.
readlines
()
for
i
in
lines
:
self
.
output
.
write
(
i
)
self
.
output
.
write
(
'
\\
newpage
\n
'
)
self
.
output
.
write
(
'
\n
'
)
# Prints section title in Latex format.
# Prints section title in Latex format.
# TODO: Instead of parsing format, get name of section through header of
# the algorithm/problem file. Capitalization should be used only for
# directories.
def
gen_title_latex
(
self
,
content
,
depth
):
def
gen_title_latex
(
self
,
content
,
depth
):
text
=
'
'
.
join
(
list
(
map
(
lambda
x
:
x
.
capitalize
(),
self
.
output
.
write
(
'
\\
'
+
self
.
hierarchy
[
depth
]
+
'
{
'
+
content
+
'
}
'
+
'
\n
'
)
content
.
split
(
'
.
'
)[
0
].
split
(
'
_
'
))))
print
(
'
\\
'
+
self
.
hierarchy
[
depth
]
+
'
{
'
+
text
+
'
}
'
)
# Prints code in Latex format.
# Prints code in Latex format.
def
gen_code_latex
(
self
,
path
):
def
gen_code_latex
(
self
,
path
):
# TODO: Add code parsing funcion and code to latex generation
# TODO: Add code parsing funcion to extract text
pass
self
.
output
.
write
(
'
\\
begin{lstlisting}[style=customcpp]
\n
'
)
with
open
(
path
)
as
f
:
lines
=
f
.
readlines
()
for
i
in
lines
:
self
.
output
.
write
(
i
)
self
.
output
.
write
(
'
\\
end{lstlisting}
\n
'
)
self
.
output
.
write
(
'
\n
'
)
# Generates Latex for entire tree recursively
# Generates Latex for entire tree recursively
def
gen_latex
(
self
,
sub
,
path
=
''
,
depth
=
0
):
def
gen_latex
(
self
,
sub
,
path
=
''
,
depth
=
0
):
if
type
(
sub
)
==
list
:
if
type
(
sub
)
==
list
:
for
i
in
sub
:
for
i
in
sub
:
self
.
gen_title_latex
(
i
,
depth
)
self
.
gen_title_latex
(
self
.
_parse_file_name
(
path
+
i
)
,
depth
)
self
.
gen_code_latex
(
path
+
i
)
self
.
gen_code_latex
(
path
+
i
)
else
:
else
:
for
i
in
sub
:
for
i
in
sub
:
self
.
gen_title_latex
(
i
,
depth
)
self
.
gen_title_latex
(
self
.
_parse_dir_name
(
i
)
,
depth
)
self
.
gen_latex
(
sub
[
i
],
path
+
i
+
'
/
'
,
depth
+
1
)
self
.
gen_latex
(
sub
[
i
],
path
+
i
+
'
/
'
,
depth
+
1
)
#self.output.write('\\newpage\n')
self
.
output
.
write
(
'
\n
'
)
# Parses name of the section (capitalize)
def
_parse_dir_name
(
self
,
name
):
return
'
'
.
join
(
list
(
map
(
lambda
x
:
x
.
capitalize
(),
name
.
split
(
'
_
'
))))
# Parses name of file by getting the first line of the source code.
def
_parse_file_name
(
self
,
name
):
with
open
(
name
)
as
f
:
result
=
f
.
readline
()
return
result
[
4
:
-
1
]
def
get_args
():
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
'
--header
'
,
action
=
'
store
'
,
type
=
str
,
help
=
'
Header of Latex file
'
)
parser
.
add_argument
(
'
--output
'
,
action
=
'
store
'
,
type
=
str
,
help
=
'
Output Latex file
'
)
return
parser
.
parse_args
()
def
main
():
def
main
():
dirs
=
[
'
algorithms
'
,
'
misc
'
]
args
=
get_args
()
tree
=
Tree
(
dirs
)
tex
=
LatexGenerator
(
tree
)
tree
=
Tree
([
'
algorithms
'
,
'
misc
'
])
tex
=
LatexGenerator
(
tree
,
args
.
output
,
args
.
header
)
if
__name__
==
"
__main__
"
:
if
__name__
==
"
__main__
"
:
main
()
main
()
This diff is collapsed.
Click to expand it.
notebook/header.tex
+
1
−
1
View file @
f1339082
\documentclass
{
article
}
\documentclass
[oneside]
{
book
}
\usepackage
{
listings
}
\usepackage
{
listings
}
\usepackage
{
titlesec
}
\usepackage
{
titlesec
}
\usepackage
[a4paper, total={6in, 8in}]
{
geometry
}
\usepackage
[a4paper, total={6in, 8in}]
{
geometry
}
...
...
This diff is collapsed.
Click to expand it.
Prev
1
2
Next
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment