To write text and output as a text file by bash commands.

In [5]:
%%bash
echo -e "program main 
implicit none 
integer i, ig 

  write(*,*) 'hello' 

end program main
" > output.f90

To write text and output as a text file by bash commands.

In [ ]:
f = open('kaigyou.txt', 'w')

str='plasma'

# Strings to be written in the text file. The word \n means to start a new line.
kaigyou_str = '\
%s\n\
collisionless shocks\n\
particle acceleration' %(str)
 
# write down on the text
f.write(kaigyou_str)
 
# clear the data
f.flush()
 
# close a connection with the text 
f.close()

To read custom.css for RISE presentation in Jupyter notebook by a full path.

In [ ]:
%%HTML
<link rel="stylesheet" type="text/css" href="http://localhost:8888/notebooks/OneDrive/Jupyter_notebook/RISE/RISE_custom.css">

To read a file from Jupyter notebook by a full path.

In [ ]:
!notepad.exe 'c:/Users/mnaka/OneDrive/Jupyter_notebook/RISE/RISE_custom.css'

To connect with a server by port forwarding.

In [ ]:
!ssh -L 8888:127.0.0.1:8888 username@IPadress
In [ ]:
 

To output a Jupyter notebook as html-based slide.

In [ ]:
%%bash 
#output html-based slides
jupyter nbconvert --to slides *****.ipynb --SlidesExporter.reveal_theme=black --SlidesExporter.reveal_scroll=True --template=/.../output_toggle.tpl --SlidesExporter.reveal_transition=convex

Equation number and Reffering

Write as follows:

$$
\begin{equation}
g = a^b f(x)dx \label{eq:1} \tag{1}
\end{equation}
$$

, and reffer as \ref{eq:1}.

$$ \begin{equation} g = a^b f(x)dx \label{eq:1} \tag{1} \end{equation} $$

See (\ref{eq:1})!

How to create PDF with a template

In [1]:
%%writefile temp.tplx
((*- extends 'article.tplx' -*))

((* block author *))
\author{Cyrille Rossant}
((* endblock author *))

((* block title *))
\title{My document}
((* endblock title *))
writing temp.tplx
Writing temp.tplx
In [ ]:
!jupyter nbconvert  --no-input ***.ipynb --to pdf --template temp

custom.css

.CodeMirror pre{
/*  font-family: Menlo, monospace !important;  */
}

.container {
    width: 95% !important;
    background: #cccccc !important;
}

.notebook_app {
    background: #cccccc !important;
}

body > #header{
    background:  #cccccc ; 
}

html, body, #container{
    background-color: #cccccc !important;
}


#notebook-container{
/*  margin: 10px;
    padding: 0px;*/
    box-shadow: none !important;
}

div.text_cell {
    font-size: 120% !important;
}


div#notebook p, div#notebook{
    line-height: 125%;
}

.rendered_html pre, .rendered_html table{
    line-height: 125%;
}

.CodeMirror, .CodeMirror pre, .CodeMirror-dialog, .CodeMirror-dialog, .CodeMirror-search-field, .terminal-app .terminal {
    font-size: 110%;
    line-height: 120%;
    background: #ffffff;
}


.jp-MarkdownOutput {
    font-size: 120% !important;
}

/*div.prompt_container{ margin-left: -10pt; }*/

/*
#notebook-container {
    padding: 5px;
}
*/

.run_this_cell {
    padding-left: 0px;
    padding-right: 0px;
}

div.input_area > div.highlight > pre{
    white-space: pre;
}

.CodeMirror-scroll{
    height: fit-content;
    margin-bottom: -50px;
    overflow: hidden !important;
}

.CodeMirror-vscrollvar, .CodeMirror-hscrollbar{
    display: none !important;
}

.rendered_html img {
  display: block;
 /* float: left;*/
 margin-left:unset;
  max-height:400px;
}

custom.js

this is based on the nbextension, cellfolding.

define([
    'base/js/namespace',
    'base/js/events'
    ], function(Jupyter, events) {
      "use strict";
      //keybindings.bindSublimeKeymap();
    //vim keybinding//
    //vim.vimkey();

      function on_click() {
        var code = $(this).parent().find(".CodeMirror")[0].CodeMirror;
        var $incell=$(this).parent().find(".inner_cell");
        var curheight =$(this).parent().find(".CodeMirror").height();
        var slideheight=28;
    //  window.alert(code.options.fold);
        if (!code.options.fold && curheight>31) {
            code.options.fold=true;
            code.setSize(null, slideheight);
            $incell.css({'border-bottom' : '2px dashed'}); 
    } else {
            code.options.fold=false;
            code.setSize(null, 'auto');
          $incell.css({'border-bottom' : 'none'}); 
    }
      }

      //add click listener for all cells
      $( ".prompt_container" ).dblclick(on_click);
      $( ".output_wrapper"   ).dblclick(on_click);

$(document).keyup(function(e) {
    switch (e.keyCode) {
        case 72:
            // Key:h 
            //$("#shortcut_button").click();
            //var f = $(this).getElementsByClassName('code_cell');
            //var strUser = f.value;
            //window.alert(strUser);
            //focus($(this));
            //var cellselected=$(this).children().find(".cell.selected");
            // Find the selected cell
            //Jupyter.notebook.command_mode();
            var cell = Jupyter.notebook.get_selected_cell();
            var val=Jupyter.notebook.mode;
            //window.alert(val);
            if(val=='command'){
              //window.alert('toggle!');    
              cell.element.children().find(".prompt_container").dblclick();
              return true;
            }
            //cell.children('.prompt_container').dblclick();
            //window.alert(cell.focus());
            break;
    };
});

      // listen for newly added cells and add a click listener
      var notebook = $( "#notebook-container" )[0];
      var observer = new MutationObserver(function(mutations) {
          mutations.forEach(function(mutation) {
            if (mutation.type == 'childList') {
              mutation.addedNodes.forEach(function(child) {
                var clickable = $(child).find(".prompt_container");
                clickable.dblclick(on_click);
                var clickable2= $(child).find(".output_wrapper");
                clickable2.dblclick(on_click);
                //console.log(clickable);
              });
            }
          });
      });
      observer.observe(notebook, {childList: true});

// toggle all cells //
        var flag1=true;
        var handler = function () {
            //window.alert(flag1);
            //var value=$(".CodeMirror")[0].CodeMirror.options.fold;
            $(".code_cell").each(function () {
                var code      =$(this).children().find(".CodeMirror")[0].CodeMirror;
                var scroll    =$(this).children().find(".CodeMirror-scroll");
                var vscrollbar=$(this).children().find(".CodeMirror-vscrollbar");
                var hscrollbar=$(this).children().find(".CodeMirror-hscrollbar");
                var incell    =$(this).children().find(".inner_cell");
                var currheight=$(this).children().find(".CodeMirror").height();
                var slideheight=28;
                //window.alert(currheight);
                if (flag1) {
                    if(!code.options.fold && currheight>31){
                        //window.alert(code.options.fold);
                        code.options.fold=true;
                          code.setSize(null, slideheight);
                          incell.css({'border-bottom' : '2px dashed'}); 
                    //flag1=false;
                   //        code.setSize(null, 'auto');
                   //   incell.css({'border-bottom' : 'none'});
                    };
               } else {
                    if(code.options.fold){
                        code.options.fold=false;
                        code.setSize(null, 'auto');
                        incell.css({'border-bottom' : 'none'}); 
                    };
                    //flag1=true;
                    // code.setSize(null, slideheight);
                   // incell.css({'border-bottom' : '2px dashed'});
                   // scroll.css({'overflow-y' : 'unset !important'});
                    //vscrollbar.css({'overflow-y': 'hidden'});
                    //hscrollbar.css({'overflow-x': 'hidden'});
               }
          });

          //  alert('this is an alert from my_extension!');
               flag1=!flag1;
             //  window.alert(flag1);
        };

        var action = {
            icon: 'fa-eye', // a font-awesome class used on buttons, etc
            help    : 'toggle cells',
            help_index : 'zz',
            handler : handler
        };
        var prefix = 'my_extension';
        var action_name = 'toggle cells';

        var full_action_name = Jupyter.actions.register(action, action_name, prefix); // returns 'my_extension:show-alert'
        Jupyter.toolbar.add_buttons_group([full_action_name]);
});
In [ ]: