Ditaa not aligning - compilation

It should be clear to know (for a human) what I want this ditaa-input file to look like
/---------------------------\
| TEST |
+--------------+------------+
| foo() | "yuck < 3" |
+--------------+------------+
| bar() | NEVEREVER! |
+--------------+------------+
| antlioneater | (x>5) || d |
\--------------+------------/
But it doesn't. Look at the less/greater signs. Plus, that is one out-of-shape antlioneater!
What am I doing wrong? I invoked ditaa v0.9 as ditaa -E -e utf8 test.txt.

I suggest using another character that looks like it, for example ‹ and ›.
It's a bit of a trick, but since the output of ditaa is an image anyway, having a visually similar character is usually good enough.
I personally use this to embed HTML markup in my ditaa charts.

Ditaa parses > and < as arrow heads even if they are not attached to a line ( --> ), hence the weird rendering. It's unfortunate, but that's how it is!

Related

Rendering this pandoc table

+---------------+---------------+--------------------+
| Right | Left | Centered |
+==============:+:==============+:==================:+
| Bananas | $1.34 | built-in wrapper |
+---------------+---------------+--------------------+
I used the standard command
pandoc test.txt -o test.pdf
But I get the above unrendered text. Am I doing something wrong here?
I am new to pandoc tables. Are grid tables fundamentally different than other tables supported by pandoc markdown?
I managed to render this adapted version in stackedit.io
| Right | Left | Centered |
|-:|:-|:-:|
| Bananas | $1.34 | built-in wrapper |
And your version in pandoc/try, which did work as expected. Try specifying the input and output format, and also try a different output format to see if that works.

Taking notes: print two pages per sheet, one blank

I need an automation for PDFs that is a variant of multiple pages per sheet. In this case, I don't need a simple two-pages-per-sheet solution, that's easy. I need to take hand-written notes side by side to the pages. So, here it goes:
Given a PDF, I'd like to print it with two pages per sheet, however, one page must be blank, like this:
+-------+-------+
| P.1 | white |
| | |
| | |
+-------+-------+
+-------+-------+
| P.2 | white |
| | |
| | |
+-------+-------+
etc.
Has anyone an idea to write a script that can automate this?
PS. I know how to do this in LaTeX, but I'd like to avoid the big gun...
If avoiding LaTeX does not mean avoiding usage of any tools that depend on it, then PDFJam (Debian package is texlive-extra-utils) could be of help, see q/a: Gluing (Imposition) PDF documents.
Otherwise you are probably better off with a little script that converts .pdf file pages to images and then merges them with a blank image, ImageMagick is able to do those things.
With Ubuntu:
# install packages
sudo apt-get install enscript ghostscript pdfjam pdftk
source="source.pdf"
output="output.pdf"
# create ps with one blank page
echo -n | enscript -p blank.ps
# convert p2 to pdf
ps2pdf blank.ps blank.pdf
# get number of pages of $source
num=$(pdftk "$source" dump_data | grep -Po 'NumberOfPages: \K.*')
# create string with new page numbers
for ((i=1;i<=$num;i++)); do pages="$pages A$i-$i B1-1"; done
# create pdf with white pages
pdftk A="$source" B=blank.pdf cat $pages output tmp.pdf
# create pdf with two pages on one side
pdfjam tmp.pdf --nup 2x1 --landscape --outfile "$output"
# clean up
rm blank.ps blank.pdf tmp.pdf
I have a solution which does not print exactly the layout which you want, but prints the page centered in the landscape sheet, like so:
+---+-------+----+
| | P.1 | |
| | | |
| | | |
+---+-------+----+
+---+-------+----+
| | P.2 | |
| | | |
| | | |
+---+-------+----+
If you're goal is to create free space for hand annotations, this layout might be better since it lets you write the annotation closer to the printed text.
The following script relies on pdfjam which uses LaTeX under the hood. Probably adding a few more command line arguments for pdfjam would get exactly what you are looking for.
#!/bin/bash
if [ "$#" -ne 1 ]; then
echo "usage: $0 PDF_filename..."
echo
echo "This script takes a PDF file as command line arguments,"
echo "and generates a new, landscape-formatted PDF file, where every "
echo "page has very large margins which may be useful for editorial notes"
echo
echo "Requires: pdfjam, which is installed by the apt-get package texlive-extra-utils"
exit 1
fi
command -v pdfjam >/dev/null 2>&1 || { echo >&2 "I require pdfjam but it's not installed. Do an apt install of texlive-extra-utils to get it on Ubuntu. Aborting."; exit 1; }
pdfjam --batch --nup 1x1 --suffix widemargin --landscape "$#"

Verbatim Text in Doxia APT Table

Using Doxia APT format, I would like to include verbatim text or a snippet within a table.
*------------+----------------------------+
|| col1 || col2 |
*------------+----------------------------+
| some text | VERBATIM TEXT OR SNIPPET |
*------------+----------------------------+
However, since doxia verbatim text and macros both must be non-indented, and the table requires preceding markup, I'm not sure if there is an easy way to accomplish this.
To be more specific, I am using Maven 3 to generate site documentation with apt documents. I would like to include multi-line JSON representations in a table column.
As a workaround, each line is monospaced and several of the json characters must be escaped, which is not easy to read or maintain (although the rendered page appears fine). For example:
*------------+----------------------------+
|| col1 || col2 |
*------------+----------------------------+
| some text | <<<\{>>>\ |
| | <<<\ "id":"12345",>>>\ |
| | <<<\ "name":"value">>>\ |
| | <<<\}>>> |
*------------+----------------------------+
Ideally, in order to maintain readability of the table, I would prefer to use a doxia snippet or similar macro to dynamically insert the code, but could also use verbatim text. For example, I would like to be able to do something like the following, which isn't valid:
*------------+-----------------------------+
|| col1 || col2 |
*------------+-----------------------------+
| some text | %{snippet|url=example.json} |
*------------+-----------------------------+
Is there any way to accomplish this?

gnu watch: justify on the lower left of the terminal

I want to apply a watch command on a mysql query every N seconds, but would like to have the results on the bottom left of the terminal instead of the top left:
watch -n 120 "mysql_query" | column -t"
Shows my results like so:
--------------------------
|xxxxxxxxxxx |
|xxxxxxxxxxx |
|xxxxxxxxxxx |
| |
| |
--------------------------
Whereas I would like them to have like so:
--------------------------
| |
| |
|xxxxxxxxxxx |
|xxxxxxxxxxx |
|xxxxxxxxxxx |
--------------------------
Suggestion?
I don't see a straight-forward way to do this, but I managed to force it to work using the following approach. I haven't fully tested this so I cannot guarantee that this will work in all situations.
Using this script:
#!/bin/bash
TERM_HEIGHT=`tput lines` # determine terminal height
WATCH_BANNER_HEIGHT=2 # account for the lines taken up by the header of "watch"
let VIS_LINES="TERM_HEIGHT - WATCH_BANNER_HEIGHT" # height of visible area
(yes " " | head -n $VIS_LINES; cat | head -n $VIS_LINES) | tail -n $VIS_LINES
Post process the output of your command as it is called by watch e.g. (assuming the script was saved as align_bottom, made executable, and store somewhere within your $PATH):
watch -n 120 "mysql_query | column -t | align_bottom"
What the script does:
Determine the height (number of lines) of the terminal
Calculate the visible area of the watch output
Print blank lines to pad the output (pushing the output down)
Read in output from stdin, and trim it so we only show the top of the output if it extends beyond the screen. If you want to see the bottom of the output instead, simple remove the head command after cat.
tail the output of steps (3) and (4) so excess padding is removed and the final output fits snugly within watch
I have to admit this seems a little hackish, but hopefully it gets you closer to what you're trying to achieve.
Update:
It should also be possible to implement that as a function instead just so it can sit comfortably in .bashrc.
function align_bottom() {
(( VIS = $(tput lines) - 2 )) # height of visible area
(yes " " | head -n $VIS; cat | head -n $VIS) | tail -n $VIS
}
typeset -fx align_bottom # !! make it callable from subshell
Usage would be the same:
watch -n 120 "mysql_query | column -t | align_bottom"
Note that watch runs the given command using sh -c, therefore, as Dennis pointed out in the comments, on systems that does not link /bin/sh to /bin/bash the function approach shown above will not work.
It is possible to make it work usign:
watch -n 120 "mysql_query | column -t | bash -c align_bottom"
but for portability and usability, it's cleaner to simply use the shell script approach.
I don't know if watch can do that, but what I'd do is use another tool to have multiple terminals and resize the one in which watch is running according to my needs.
A couple of these tools that can be useful are:
screen
byobu (screen with some enhancements)
terminator
I hope this helps.

Problem with including an "image" in shell program

I'm writing a program where at some point in my loop I want to print to output whatever is stored in a separate file (an image). But if I code it like this:
for c in $LIST
do
clear
./image.0
done
And the "image.0" file contains only an image like this:
+----+
| |
|
|
|
|
|
========
Then when I run my program I get this message:
./image.0: 1: +----+: not found
./image.0: 2: Syntax error: "|" unexpected
Why?
================================
So "cat" works, the image appears in the output but it's shifted in a strange way.
Do you know why this would happen?
+----+
| |
|
|
|
|
|
========
Answer: I put printf "\n" that fixed the shifting image
With ./image.0, you tell the shell to execute the image. You want to output it, so use cat image.0
Try to use the command cat to output the content of the image.0 file
cat ./image.0
./something will take something as a program and execute it. That's not what you want : to display the contents of a file, you can use the cat command, like this :
for c in $LIST
do
clear
cat image.0
done

Resources