Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F102271929
platex2slides
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Tue, Feb 18, 23:38
Size
2 KB
Mime Type
text/x-python
Expires
Thu, Feb 20, 23:38 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
24320885
Attached To
R3683 Slides
platex2slides
View Options
#!/bin/env python3
import
sys
import
nbformat
from
PythonLatex.latex_structure
import
LatexStructure
from
PythonLatex.latex_structure
import
LatexEnvironment
filename_in
=
sys
.
argv
[
1
]
filename_out
=
sys
.
argv
[
2
]
tex_struct
=
LatexStructure
()
tex_struct
.
parseLatexFile
(
filename_in
)
print
(
str
(
tex_struct
))
nb
=
nbformat
.
notebooknode
.
NotebookNode
({
u'nbformat_minor'
:
2
,
u'cells'
:
[],
u'nbformat'
:
4
,
u'metadata'
:
{
u'kernelspec'
:
{
u'display_name'
:
u'Python 2'
,
u'name'
:
u'python2'
,
u'language'
:
u'python'
},
u'toc'
:
{
u'nav_menu'
:
{
u'width'
:
u'252px'
,
u'height'
:
u'12px'
},
u'toc_window_display'
:
False
,
u'widenNotebook'
:
False
,
u'toc_section_display'
:
u'block'
,
u'colors'
:
{
u'hover_highlight'
:
u'#DAA520'
,
u'running_highlight'
:
u'#FF0000'
,
u'selected_highlight'
:
u'#FFD700'
},
u'navigate_menu'
:
True
,
u'number_sections'
:
True
,
u'threshold'
:
4
,
u'moveMenuLeft'
:
True
,
u'sideBar'
:
True
,
u'toc_cell'
:
False
},
u'hide_input'
:
False
,
u'language_info'
:
{
u'mimetype'
:
u'text/x-python'
,
u'nbconvert_exporter'
:
u'python'
,
u'version'
:
u'2.7.13'
,
u'name'
:
u'python'
,
u'file_extension'
:
u'.py'
,
u'pygments_lexer'
:
u'ipython2'
,
u'codemirror_mode'
:
{
u'version'
:
2
,
u'name'
:
u'ipython'
}}}})
nb
[
'cells'
]
=
[]
################################################################
def
createNewCell
():
print
(
'create new cell'
)
new_cell
=
nbformat
.
notebooknode
.
NotebookNode
()
new_cell
[
'cell_type'
]
=
'markdown'
new_cell
[
'source'
]
=
''
new_cell
[
'metadata'
]
=
{}
nb
[
'cells'
]
.
append
(
new_cell
)
return
new_cell
################################################################
current_cell
=
None
for
c
in
tex_struct
.
content
:
if
current_cell
is
None
:
current_cell
=
createNewCell
()
if
isinstance
(
c
,
LatexEnvironment
):
current_cell
=
createNewCell
()
print
(
'AAA:'
,
type
(
c
),
str
(
c
))
print
(
'adding:'
,
type
(
c
),
str
(
c
))
current_cell
[
'source'
]
+=
str
(
c
)
# print(nb)
# print(type(nb))
nbformat
.
write
(
nb
,
'test.ipynb'
)
Event Timeline
Log In to Comment