Combine eqn math in pic labels - groff

I want to add math equations to pic labels.
How can I write such a thing, for example
box "This is an $1 over 2$ test" "using math in pic labels"
. I know of ctan circuit_macros, but that would require a tex document. I want the document to stay in roff -ms format.
For example the output of
printf ".EQ\n1 over 2\n.EN" | eqn |groff -Tps > 1over2.ps
is what you see below.
I will try my luck with macros... or is there some inline way to define .EQ text?

Sorry guy's you are too slow. The solution comes with inline equations, defined by delimiters:
printf '.PS\nbox "This is an A1 over 2B test" ""'\
'"using math in pic labels" wid 2 ht .7\n.PE' |
pic|eqn -Tps -dAB | groff -Tps > testbox.ps
gives:

Related

How to render characters instead of hex? (\x60)

I have a file (file.txt) with this content:
file.txt:
+ "Chapter 8\n“So Much More Than Just an ‘A’”: A Transformative High School and University Writing Center Partnership
+ "Chapter 9\n“Oh, I Get By with a Little Help from My Friends”: Short-Term Writing Center/Community Collaborations"
My code extracts certain data from this with gawk, and then writes the results to a new file (nav.txt) using printf.
nav.txt:
Chapter 8 \xE2\x80\x9CSo Much More Than Just an \xE2\x80\x98A\xE2\x80\x99\xE2\x80\x9D: A Transformative High School and University Writing Center Partnership
Chapter 9 \xE2\x80\x9COh, I Get By with a Little Help from My Friends\xE2\x80\x9D: Short-Term
Does anyone know why the special characters (like ‘, -, etc) render as these weird hex codes? (\xE2\x80\x98A, \xE2\x80\x9D, etc)
If so, how can I output the correct characters to nav.txt, instead of their hex equivelants?
my gawk code, running on Ubuntu:
gawk '
match($0, /^[\|\+-].*"([^"]+)".*#([[:digit:]]+)/, m) {
printf "<li>\n %s\n </li>\n", m[2], m[1] >> "nav.txt"
}
' file.txt

Remove all occurrences of a list of words vim

Having a document whose first line is foo,bar,baz,qux,quux, is there a way to store these words in a variable as a list ['foo','bar','baz','qux','quux']and remove all their occurrences in a document with vim?
Like a command :removeall in visual mode highlighting the list:
foo,bar,baz,qux,quux
hello foo how are you
doing foo bar baz qux
good quux
will change the text to:
hello how are you
doing good
A safer way is to write a function, check each part of your "list", if there is something needs to be escaped. then do the substitution (removing). A dirty & quick way to do it with your input is with this mapping:
nnoremap <leader>R :s/,/\|/g<cr>dd:%s/\v<c-r>"<c-h>//g<cr>
then in Normal mode, when you go to the line, which contains deletion parts and must be CSV format, press <leader>R you will get expected output.
The substitution would fail if that line has regex special chars, like /, *, . or \ etc.
Something like this one liner should work:
:for f in split(getline("."), ",") | execute "%s/" . f | endfor | 0d
Note that you'll end up with a lot of trailing spaces.
edit
This version of the command above takes care of those pesky trailing spaces (but not the one on line 2 of your sample text):
:for f in split(getline("."), ",") | execute "%s/ *" . f | endfor | 0d
Result:
hello how are you
doing
good

Awk for a fortran output

sorry for the probably too easy question, but I am a beginner in this.
I have a FORTRAN output that looks somewhat like this:
xxxx 3.54D+05 yyyy
xxxx 3.89D+08 yyyy
xxxx 2.45D-04 yyyy
...
...
I would like to print the logarithm of the second column, but awk does not recognize this form of scientific notation. Any suggestions?
Thank you!
I don't have my Mac to hand to test this, but in the interests of getting you started, I'll have a try off the top of my head...
awk '{x=$2; sub(/D/,"e",x); print log(x)}' file
Hopefully that will pick up column 2 into variable x and then replace the D by e, get the log and print it... then again it may say "bailing at line 1 because Mark is clueless"....

How do I create a sub arrary in awk?

Given a list like:
Dog bone
Cat catnip
Human ipad
Dog collar
Dog collar
Cat collar
Human car
Human laptop
Cat catnip
Human ipad
How can I get results like this, using awk:
Dog bone 1
Dog collar 2
Cat catnip 2
Cat collar 1
Human car 1
Human laptop 1
Human ipad 2
Do I need a sub array? It seems to me like a need an array of "owners" which is populated by arrays of "things."
I'd like to use awk to do this, as this is a subscript of another program in awk, and for now, I'd rather not create a separate program.
By the way, I can already do it using sort and grep -c, and a few other pipes, but I really won't be able to do that on gigantic data files, as it would be too slow. Awk is generally much faster for this kind of thing, I'm told.
Thanks,
Kevin
EDIT: Be aware, that the columns are actually not next to eachother like this, in the real file, they are more like column $8 and $11. I say this because I suppose if they were next to eachother I could incorporate an awk regex ~/Dog\ Collar/ or something. But I won't have that option. -thanks!
awk does not have multi-dimensional arrays, but you can manage by constructing 2D-ish array keys:
awk '{count[$1 " " $2]++} END {for (key in count) print key, count[key]}' | sort
which, from your input, outputs
Cat catnip 2
Cat collar 1
Dog bone 1
Dog collar 2
Human car 1
Human ipad 2
Human laptop 1
Here, I use a space to separate the key values. If your data contains spaces, you can use some other character that does not appear in your input. I typically use array[$a FS $b] when I have a specific field separator, since that's guaranteed not to appear in the field values.
GNU Awk has some support for multi-dimensional arrays, but it's really just cleverly concatenating keys to form a sort of compound key.
I'd recommend learning Perl, which will be fairly familiar to you if you like awk, but Perl supports true Lists of Lists. In general, Perl will take you much further than awk.
Re your comment:
I'm not trying to be superior. I understand you asked how to accomplish a task with a specific tool, awk. I did give a link to the documentation for simulating multi-dimensional arrays in awk. But awk doesn't do that task well, and it was effectively replaced by Perl nearly 20 years ago.
If you ask how to cross a lake on a bicycle, and I tell you it'll be easier in a boat, I don't think that's unreasonable. If I tell you it'll be easier to first build a bridge, or first invent a Star Trek transporter, then that would be unreasonable.

escaping characters for substitution into a PDF

Can anyone tell me the set of control characters for a PDF file, and how to escape them? I have a (non-deflated (inflated?)) PDF document that I would like to edit the text in, but I'm afraid of accidentally making some control sequence using parentheses and stuff.
Thanks.
Okay, I think I found it. On page 15 of the PDF 1.7 spec (PDF link), it appears that the only characters I need to worry about are the parentheses and the backslash.
Sequence | Meaning
---------------------------------------------
\n | LINE FEED (0Ah) (LF)
\r | CARRIAGE RETURN (0Dh) (CR)
\t | HORIZONTAL TAB (09h) (HT)
\b | BACKSPACE (08h) (BS)
\f | FORM FEED (FF)
\( | LEFT PARENTHESIS (28h)
\) | RIGHT PARENTHESIS (29h)
\\ | REVERSE SOLIDUS (5Ch) (Backslash)
\ddd | Character code ddd (octal)
Hopefully this was helpful to someone.
You likely already know this, but PDF files have an index at the end that contains byte offsets to everything in the document. If you edit the doc by hand, you must ensure that the new text you write has exactly the same number of characters as the original.
If you want to extract PDF page content and edit that, it's pretty straightforward. My CAM::PDF library lets you do it programmatically or via the command line:
use CAM::PDF;
my $pdf = CAM::PDF->new($filename);
my $page_content = $pdf->getPageContent($pagenum);
# ...
$pdf->setPageContent($pagenum, $page_content)l
$pdf->cleanoutput($out_filename);
or
getpdfpage.pl in.pdf 1 > page1.txt
setpdfpage.pl in.pdf page1.txt 1 out.pdf