Cross referencing in jupyter notebook - jupyter-notebook

in Jupyter notebook, is it possible to cross-reference a heading number in the markup cell.
For example, I have a paragraph like " As explained in Section 1.1... "
1.1 is a heading number. If I insert another heading above heading 1.1 , then the cross-reference should automatically change to 1.2 , like what happens in MS word

Related

Cells in Jupyter notebooks

I am trying to parse a pdf using PyPDF2 in a Jupyter notebook. Below is how I would like to write the different parts of the code, that is, the extract text statements in one cell and the RegEx in a new cell. However, if I separate the two pieces of code as below, the RegEx only runs through the last page of the file and not through the whole file (12 pages). Why does this happen? I would really like to use different cells.
import PyPDF2
import re
file = open(r'file.pdf', 'rb')
doc = PyPDF2.PdfFileReader(file)
#print(doc.getNumPages())
#new cell
for i in range(0, 12):
page = doc.getPage(i)
text = page.extractText()
#print(text)
#new cell
doc_re = re.compile(r'S\d+_\d+', re.IGNORECASE)
result = doc_re.findall(text)
print(result)
Each time you run your for loop, you're resetting the value of text by using text = page.extractText()
The RegEx is running on what you give it, which is text. Even though your loop runs over 12 pages, the second cell of code receives the final value of text (which is whatever you assign it to be on the last iteration of the loop).
You can either move the code from your second cell inside of your for loop, or a better option would be to add each page's text to text.
So, turning text = into text += should solve your problem.

Create new emphasis command R Markdown

In R Markdown, to make a text bold, we just need to do:
**code**
The the word code shows in bold.
I was wondering if there is a way to create a new command, let's say:
***code***
That would make the text highlighted?
Thanks!
It is not easily possible to create new markup, but one can change the way existing markup commands are rendered. Text enclosed by three stars is interpreted as emphasized strong emphasis. So one has to change that interpretation and change it to something else. One way to do so is via pandoc Lua filters. We just have to match on pandoc's internal representation of emphasized strong text and convert it to whatever we want:
function Strong (strong)
-- if this contains only one element, and if that element
-- is emphasized text, convert it to highlighted text.
local element = #strong.content == 1 and strong.content[1]
if element and element.t == 'Emph' then
table.insert(element.content, 1, pandoc.RawInline('html', '<mark>'))
table.insert(element.content, pandoc.RawInline('html', '</mark>'))
return element.content
end
end
The above works for HTML output. One would have to define what "highlighted text" means for each targeted format.
See this and this question for other approaches to the problem, and for details of how to use the filter with R Markdown.

Nested numbered list do not break line in Jupyter Notebook Markdown

I'm trying to create a nested numbered list within a Jupyter Notebook Markdown cell for use as a table of contents which links to titles in the document. However the items in the list which should be nested/indented just appear on the same line when the cell has been executed.
I have tried using four spaces before the numbers I want indenting (which is what I've seen people suggesting). This didn't work so I also tried 1-3 spaces and using a tab but none seem to work. Thought it may be an issue with the numbering itself and the use of fullstops (i.e. "1." and "1.1" , and not "1.1." etc), but this doesn't fix the issue either.
The indent does work if i use an asterisk in place of 1.1, 1.2 etc., but this is not the format I want.
Markdown code example:
1. [Intro](#intro)
1.1 [Part A](#pA)
1.2 [Part B](#pB)
1.3 [Part C](#pC)
2. [Main](#main)
This code outputs:
1. Intro 1.1 Part A 1.2 Part B 1.3 Part C
2. Main
Desired output:
1. Intro
1.1 Part A
1.2 Part B
1.3 Part C
2. Main
You need to add one of the following:
two white spaces at the end of each line, or
a <br> tag at the end of each line.
for instance:
1. [Intro](#intro)<br>
1.1 [Part A](#pA)<br>
1.2 [Part B](#pB)<br>
1.3 [Part C](#pC)<br>
2. [Main](#main)<br>
Results:
To create a numbered list, enter 1. followed by a space, for example:
1. Numbered item
1. Numbered item
For simplicity, you use 1. before each entry. The list will be numbered correctly when you run the cell.)
To create a substep, press Tab before entering the numbered item, for example:
1. Numbered item
1. Substep
Source (scroll down to "Numbered lists"): https://www.ibm.com/docs/en/watson-studio-local/1.2.3?topic=notebooks-markdown-jupyter-cheatsheet

how to split and change the font style of a crystal report element?

we are having a report generated using crystal report While generating we have a request to have a checkbox with a list of items.
The checkbox is only available in the Wingdings font.
Since we are using Arial font for the list items we can not change the font of the formula field through which we are showing the list.
Eg:
[] task1
[x] task2
we need to split each list item and replace the square brackets with checkbox form the wingdings font.
how can we create a formula for this in crystal report?
I found a way
Create a formula with this code:
stringvar MYARRAY:= Replace ({Notes1},"[]" , '< font face = "wingdings" >'&chr(254)&'< /font>');
stringVar MYARRAY1 := ' '+Replace (MYARRAY,"|" ,' < br> );
MYARRAY1;
Drag and drop this field on the report > right-click the field > Format Field > Paragraph tab > Under "Text Interpretation" select "HTML Text".
Without using HTML or RTF Text interpretation, Crystal Reports can't display two fonts in one formula field, but it is possible with a Text Object.
Create two formulas, one with the checkmark and one with the item-text.
Drag & drop the formula-fields into an empty text object.
Now you can format the two formula fields independently of each other but inside the same field.

Ipython notebook on 2 columns

I'd like to have to have cells of a python notebook on 2 columns, for writng annotations next to code (for example, instead of inserting 2 cells below, I would insert I insert a cell on the right and a cell below on the left)
I know that it's possible to use custom css for changing the appearance (e.g https://github.com/nsonnad/base16-ipython-notebook/blob/master/ipython-3/output/base16-3024-dark.css ), is it possible also for the layout?
On the other hand, I found an example of how to use the css for creating a table layout (https://pixelsvsbytes.com/2012/02/this-css-layout-grid-is-no-holy-grail/), but not being very familiar with CSS I don't understand if this can be applied to an unknown number of equal blocks (unknown because they are generated interactively by the user). For reference, here is how currrently looks like:
You could just change the cells to markdown or raw and make them float right.
from IPython.core.display import HTML
HTML("<style> div.code_cell{width: 75%;float: left;}"
+"div.text_cell{width: 25%;float: right;}"
+"div.text_cell div.prompt {display: none;}</style>")
Now when you enter a cell and want it on the right press esc-r (or m).
esc- unselects it and allows the notebook to process commands. r is the command to make a raw cell.

Resources