Converting jupyter notebook to PDF removes table structure - jupyter-notebook

I am trying to make a pdf file from my jupyter notebook, when i choose the PDF via LaTeX option, after the generation of pdf file, the structure of the table disappears. What can be done to prevent this issue?
Here is the markdown code of my table :
| Col1 | Col2 |
| ----------- | ----------- |
| line1<br> line2 | line_1<br> line_2 |
| another line | some text |
Here is the output in jupyter notebook :
And here is the generated table in the pdf file :
As you can see line1 and line2 are written in a single line in the pdf file.

Related

Is read/write offset in per process table or open file table?

When I prepare for my exam, I meet the following statement:
If file1 and file2 are hard linked, and two processes open file1 and file2,
their read/write pointer keeps the same.
Which, according to the answer (no explanation), is wrong. So I searched google, and found something different.
This link: https://www.usna.edu/Users/cs/wcbrown/courses/IC221/classes/L09/Class.html Says the read/write pointer is in the (system wide) open file table.
But this link http://www.cs.kent.edu/~walker/classes/os.f08/lectures/Walker-11.pdf
Says the pointer is in the per process file table.
Which one is true?
IHMO, the read/write offset clearly has to be a per process property. You could easily crash other proceses if this was a system wide per file property. This is my understang, but I'd rather have this confirmed by an informed source.
I took a look at the 1986 AT&T book "The design of the Unix Operating System" by Maurice J. Bach, which I consider a informed source.
In topic 2.2.1 An Overview of the File Subsytem it sais:
... Inodes are stored in the file system ... The kernel reads them
into an in-core inode table when manipulating files ... The kernel
contains two other data structures, the file table and the user
file descriptor table. The file table is a global kernel
structure, but the user file descriptor table is allcated per
process ... The file table keeps track of the (read/write) byte
offset ...
This would contradict my statement. But then, clarification can be read in topic 5.1 OPEN, pages 92ff. Figure 5.3 shows an example of a process having done three opens, two of them being for the same file, /x/y/z (I simplfy the naming here, and in the illustration below).
User File
Descriptor Table File Table inode Table
+--------------+ +------------+ +------------+
0| | | | | |
+--------------+ | . | | . |
1| | | . | | . |
+--------------+ | . | | . |
2| | +------------+ | |
+--------------+ +-->| read offset|----+ | |
3| | | +------------+ | | |
+--------------+ | | | | +------------+
4| |---+ | . | +->| inode of |
+--------------+ | . | +--->| /x/y/z |
5| |----+ | . | | +------------+
+--------------+ | +------------+ | | . |
6| |-+ +->| read |----+ | . |
+--------------+ | +------------+ | | | . |
| . | | | . | | | +------------+
| . | | | . | | +->| inode of |
| | | | . | | | /a/b |
+--------------+ | +------------+ | +------------+
+---->|write offset|--+ | . |
+------------+ | . |
| . | | . |
| . | | . |
+------------+ +------------+
The final answer is in the text following figure 5.3 on page 94:
Figure 5.3 shows the relationship between the inode table, file
table, and user file descriptor table structures. Each open
returns a file descriptor to the process, and the corresponding entry
in the user file descriptor table points to a unique entry in the
kernel file table even though one file (/x/y/z) is opened twice.
To answer your question: The read/write offset is kept in the kernel file table, not in a per process table, but a unique entry is allocated upon each open().
But, why is there a kernel file table? After all, the read/write offsets could have been stored in the per process user file descriptor table, instead of in a kernel table, couldn't they?
To understand why there is a kernel file table, think of what the dup() and fork() functiones do with respect to file descriptors: They duplicate the state of an open file. Under a new file descriptor in the same process, dup(), or under the same file descriptor (number) but in a duplicated user file descriptor table in the new (child) process. In both cases, duplicating the state of an open file includes the read/write offset. So for these cases, more than one file descriptor will point to a single file table entry.

Display code in two columns in restructured text

Using restructured text, how can I display two code blocks side by side, so that they can be compared line by line?
Here is an example of what I mean from this similar question for Markdown: How to disply two markdown code blocks side by side
Ok, so I found that the following works:
+-------------------------+-------------------------+
| | |
|.. code-block:: |.. code-block:: |
| | |
| # Code example 1 | # Code example 2 |
| | |
+-------------------------+-------------------------+
This creates a table with two columns, and puts a code block in each of them. If the two blocks have the same number of lines, they will be aligned to each other. The output looks like this:
If one wants to include an external script, it can be done like this:
+--------------------------------+--------------------------------+
| | |
|.. literalinclude:: script_1.py |.. literalinclude:: script_2.py |
| | |
+--------------------------------+--------------------------------+

bookdown figure caption width?

I've just started writing my PhD thesis in Bookdown and so far things are going great. The one problem I do have though is that figure captions when outputted to PDF format seem to take up only about 60% of the page width, and are centered. This is great for short captions, but most of my figure captions are in the region of 50 words long for complicated panels. Is there some LaTeX magic to make them the width of the page?
Thanks
Tom
Here is what I'm using in my .md file:
| Reagent | Amount |
| ------------------------ | -------- |
| Appropriate Buffer (10x) | 1x |
| DNA | 50-500ng |
| Restriction Enzyme | 1*U* |
| Water | - |
Table: (\#tab:restriction-generic) Schematic for restriction digestion with a single restriction enzyme.
You can make use of the LaTeX package caption:
---
output:
bookdown::pdf_document2
header-includes:
- \usepackage[width=\textwidth]{caption}
---
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
| Reagent | Amount |
| ------------------------ | -------- |
| Appropriate Buffer (10x) | 1x |
| DNA | 50-500ng |
| Restriction Enzyme | 1*U* |
| Water | - |
Table: (\#tab:restriction-generic) Schematic for restriction digestion with a single restriction enzyme. Some really long text that shows how the caption is formatted when it takes multiple lines.
Output:

Looping through the content of a file in RobotFramework

How can I loop through the contents of a file within Robot Framework?
My file contents would be like this:
1001
1002
1003
1004
I want to read the contents one by one, assign it to a variable and then do some operations with it.
Robotframework has several built-in libraries that add a lot of functionality. Two that you can use for this task are the OperatingSystem library and the String library.
You can use the keyword Get File from the OperatingSystem library to read the file, and you can use the Split to Lines keyword from the String library to convert the file contents to a list of lines. Then it's just a matter of looping over the lines using a for loop.
For example:
*** Settings ***
| Library | OperatingSystem
| Library | String
*** Test Cases ***
| Example of looping over the lines in a file
| | ${contents}= | Get File | data.txt
| | #{lines}= | Split to lines | ${contents}
| | :FOR | ${line} | IN | #{lines}
| | | log | ${line} | WARN
This solve my issue same like yours !
${File}= Get File Path\\FileName.txt
#{list}= Split to lines ${File}
:FOR ${line} IN #{list}
\ Log ${line}
\ ${Value}= Get Variable Value ${line}
\ Log ${Value}
I am reading from 'text' file and 'Get Variable Value' is part of builtin library. Thanks!
Below is a list of different examples how to use FOR & While loops in your Robot Framework Test Cases.
http://robotframework.googlecode.com/svn/tags/robotframework-2.5.3/atest/testdata/running/for.txt
My strategy, that I've used successfully with .csv files, would be to create a Python-based keyword that will grab the nth item in a file. The way I did it involved importing the CSV Python library, so to give a more complete answer I'd have to know what file type you're trying to read from.

Line count not working as expected in Unix

I am trying to get the line count to a variable. The source file filename.dat contains 2 lines of records as:
112233;778899
445566
Script 1
line_cnt=$(more /home/filename.dat | wc -l)
echo $line_cnt
When I run this script, I get the output of 2. Now, I have a modified version:
Script 2
filename=/home/filename.dat
line_cnt=$(more ${filename} | wc -l)
echo $line_cnt
The input file has the same records. But this is giving me an output of 5 even though it has only 2 records.
Can someone tell me what is wrong?
Edit - Corrected the file path in 2nd script
line_cnt=`cat ${filename} | wc -l`
The cat ${filename} | wc -l should be within back quotes.

Resources