Showing posts with label pdf. Show all posts
Showing posts with label pdf. Show all posts

Monday, August 7, 2023

bibliography example

I've saved some articles and books, and put the references into a BIB file. I want a works cited (MLA) or references (APA) page at the end of an article I'm writing. What are the basics

The TEX file and the BIB file are joined at the hip and neither will compile if they're not entirely clean of syntactic errors. It's a state of near-continual anxiety.

1. the TEX file

# pacman -S texlive-bibtexextra

In the TEX heading...

\usepackage[style=mla,backend=bibtex]{biblatex}
\addbibresource{foo.bib}

In the TEX article, whenever we cite something we get the citations key number from the BIB file. In this case, lets say our citation for some article is "z023". Then...

\cite{z023}

At the end of the TEX file, just before "\end{document}"...

\printbibliography

2. The procedure

  1. check the BIB file for underscores and syntax errors. Jabref can sometimes help with this. If there are failures, just come back to this step and clean the BIB file again and again.
  2. ensure the BIB file is locatable in the \addlibresource filepath.
  3. run the TEX a first time, using the build menu "Latex -> PDF" option (pdflatex)
  4. run the TEX a second time, using the build menu "Bibtex" option (creates the BLG)
  5. run the TEX a third time using the "Latex -> PDF" option (pdflatex)

Sunday, August 6, 2023

library, bib, and pdflatex

Oh bibliographies. Yuck

do not use underscores in file names

Underscores are tidier than camel-case and I have relied on them over and over throughout the years. They met their match with LaTeX. I no longer use them for any filename in case I need to cite it in a LaTeX document.

old
20230705_smogreceipt
new
20230705smogreceipt

successful process

Using Geany or whatever...

  1. check the bib file for underscores and cleanness
  2. have the BIB file reachable by the filepath in \addlibresource
  3. run the TEX a first time, using the build menu "Latex -> PDF" option (pdflatex)
  4. run the TEX a second time, using the build menu "Bibtex" option (creates the BLG)
  5. run the TEX a third time using the "Latex -> PDF" option (pdflatex)

bibliography failures

Bibtex and/or pdflatex fail in different ways with underscores, but by far the worst problem is the cascade failure coming from bibtex. Pdflatex makes a call to bibtex and bibtex returns a BLG file. Any underscores in the "notes" field --eg filenames -- will be included, and pdflatext will reject the entire bibliography for one underscore. This is because pdflatex requires underscores to be preceeded by either a backslash or a $ (math mode). Sometimes an underscore from bibtex causes the entire PDF not to be written by pdflatex.

Accordingly, the data retention plan described in the prior post should not rely on filenaming using underscores. The URL field is the only exception. Bibtex or pdflatex will fail downstream

BIB specific fail

There's also a way bibtex can fail independently of pdflatex. In that case, it fails to send a BLG to pdflatex at all. This comes from the "crossreference" field often used by ppl to store notes about file locations of their saved journals and so on. When the Bibtex subroutine runs, it attempts to verify this location, even going through the Web or whatever. It's obviously not going to locate the thumbdrive folder that you left yourself a note about. And thus from one "crossref" failure, it will fail to produce a BLG file. Thus no bibliography.

BIB file include

Generally, author, title, date, url (can use underscores), DOI, abstract, pages, ISBN or ISSN. Leave out notes and crossref.

Populate your bib files with all the information to span whatever style you've decided upon (MLA, APA, etc), but never include or enter anything into the "crossref" field, which causes large problems when finally compiling via bibtex

This way, if a publisher does eventually look at the work, a person can reformat their TEX file to use that style of citation. Some of this is manual decision making.

Note that large organizations like grammarly.com probably are influencers and have inertia, so they might be a good resource to consider, eg this MLA v APA page. Works cited (MLA) and Reference (APA) is a key distinction. Frankly, I believe the format should be listed along with the title to keep people from being confused.

LaTeX integration of BIB

Once all of these are connected, how do we work them into our LaTeX documents. What codes do we need? How can we have consistent citations? For one thing, the document doesn't need to access the articles, just the BIB file. Yes, we need to look those, and typically save the research articles somewhere, but the document doesn't need any of that to compile, it just needs BIB file access.

In Arch, probably need the 37Mbbiblatex package to get anything to compile.

# pacman -S texlive-bibtexextra

More is described here, but the basics...

  • package -- \usepackage[style=mla,backend=bibtex]{biblatex}
  • BIB file -- underneath package \addbibresource {BIB filename}. Append the path to the filename if it's in a different directory.
  • Inline citations -- use \cite{[BIB item key]}. This can be alpha-numeric. No underscores of course.
  • Multiple BIBS -- described here.

bibliography checklist

NO UNDERSCORED ANYTHING IN ANY BIB FILE EXCEPT THE "URL" FIELD WITHIN ITS CURLY BRACES.

DO NOT SAVE ANY DOCUMENTS WITH UNDERSCORES, NOR NAME TEX OR BIB FILES WITH UNDERSCORES. Bibliographies will not print.

Order: pdflatex, bibtex, pdflatex.

Bibtex itself fails if any file in "crossref" field cannot be located within it.

Wednesday, March 22, 2023

DOC to PDF

Found an old drive. Had some docs. Who would upload these to Drive for online scanning? Had to install LibreOffice for the offline CLI solution from this page.

lowriter --convert-to pdf --outdir [output-directory] input-doc-or-docx-file

I left off the directory flag and it just put the PDF in the same directory the DOC file was in. Obviously a person can just open each document after the damage of installing the entire 700Mb LibreOffice suite for a f*cking CLI command, but that's even worse.

I will of course have zero use of use of LibreOffice proper, so this command line option is very expensive in terms of disk space, but so far only way I know to offline convert old DOC's.

Sunday, August 30, 2015

managers: system, session, window, volume, preference (and some use a display)

Links: using systemd as a session manager ::
I miss the SysV days when system, session, window (eg. "compositing"), volume, preference, and display managers were all cleanly defined. In fact, we never even needed the preference manager, gconf, because configurations were done with simple text files for each app. I'm just a regular user, and it takes me a lot of work these days to keep these managers separate or find their configuration files. They also seem to intertwine on occasion, requiring detangling time, as well.

Display Manager Disclaimer

Logins, startx, and shutdown are the only terminal commands needed in a normal session. Display Managers are only needed to make these more aesthetic. Accordingly, I haven't used a display manager in ten years. Why have an aesthetic login if it costs memory and potential fails? Second, not using it removes one variable from the kludge of 6 managers just listed above. Display Managers inadvertently obscure any start-up fails by keeping text log access out of sight. That's a problem during an install. In fact, during installs, I obtain a solid Runlevel 2 before downloading any X elements.

Session manager sussed-out

I attempted to tweak Evince's default zoom level the other day without gvfs (gnome's volume manager) installed. Sadly, Evince does not use old-skool config files; users have to set "schema keys", which are probably xml files. At any rate, one starts at the top, the correct schema, and then one modifies its key: find the schema, then its possible keys. To shorten the codeblock below, here were the two Evince-related schemas using the list-schema flag :
$ gsettings list-schemas
org.gnome.Evince.Default
org.gnome.Evince
And then the keys for those schemas.
$ gsettings list-keys org.gnome.Evince
document-directory
auto-reload
override-restrictions
page-cache-size
allow-links-change-zoom
pictures-directory
show-caret-navigation-message

$ gsettings list-keys org.gnome.Evince.Default
window-ratio
continuous
fullscreen
show-toolbar
show-sidebar
dual-page-odd-left
inverted-colors
zoom
sidebar-page
sidebar-size
dual-page
sizing-mode
It appears the "zoom" key is the one to set, which is in schema Evince.Default.
$ gsettings set org.gnome.Evince.Default zoom 1.0
$ gsettings get org.gnome.Evince.Default zoom
1.0
We can see the zoom was set correctly (to 100%). Now let's run Evince:
$ evince
GDBus.Error:org.freedesktop.DBus.Error.ServiceUnknown: The name org.gnome.SessionManager was not provided by any .service files
Evince starts, but spawns the error above and only the default zoom factor, instead of the 100% zoom I entered.

Was gnome-session not running, sharing with systemd, or what? A simple setting can often means days of frustration in Linux. If I recall correctly, it's further the case, that gnome-session can only be started after dealing with PAM, like via gdm-password. It's unlikely any gnome sessions are running.
# ps -A |grep -i g
614 ? 00:00:00 gconfd-2
3602 pts/2 00:00:00 grep
31658 ? 00:00:00 gnome-pty-helpe
Now it's clear: no gnome-session is running. The gsetting commands were accepted. That is because, for the settings to be entered, only gconfd, gnome's preference manager, had to be running. However, there was no way to implement those preferences, because the session manager, gnome-session, was not running: an error message was generated. Meanwhile, Arch recommends against any gconf schemas, and notes they will soon be replaced with "dconf". Currently then, Evince is probably caught in the middle of these. We really have no way to configure Evince without getting a session manager going, which in turn probably requires the dreaded gvfs by the way.

Okular

In spite of the immense KDE libraries necessary for Okular, I have to look. I mean if I can just set preferences at this point, I'd be happy.




Saturday, August 15, 2015

[solved] first run of zotero back-up

I had a chance to recently attempt my first Zotero back-up and resoration. I have the stand-alone version, which I then link to a few browsers with browser plug-ins (see bottom of page). In other words, Zotero installs as a regular application, available on or offline. Zotero browser-plugins (typically XPI) install into the desired browser independent of whether Zotero is installed on one's system at all.

other bibliography/citation-related notes

BibTex tutorial :: exporting cite keys from Zotero :: helping cite keys match database


Overview

From what I could tell from Zotero's instructions, all I would need to do is backup my entire Zotero directory, and then put it in the new drive. Helpful, but experience showed it could be broken down more explicitly:
  1. Back-up the Zotero database directory (usually a few hundred MB; mine fits on a CD).
  2. Install a blank version of Zotero, on the new drive. Be sure Zotero is stable (open and close it a couple times).
  3. Add a browser connector, if you want or need one (optional).
  4. Take the backed-up data directory and overwrite the fresh install's data directory.
  5. Open Zotero and all backed-up citations should be there.
  6. Associated back-up issue: suppose one has a folder with several Ebooks or PDF's on some subject. Zotero can apparently store local HDD links to these documents, as well as metadata about the them. These links will also be in the Zotero database, just like web links, and using links uses less space in the database than the full documents would use. However, after backing up Zotero on a new install, you'll also need to duplicate the directory structure where these documents are kept. In this way, Zotero's links will point to the documents.

Back-up

Initially, I made a mistake. I backed-up the Zotero directory, burning it onto a DVD with other data. This directory and all files within it were suspiciously only about 10MB. Eventually I determined I had only backed-up the application directory. The data directory is what should be backed-up. But the data directory is not in plain sight within the directory structure. To find the data directory, I searched for one of its files, zotero.sqlite:
$ find -name zotero.sqlite
./.zotero/zotero/af5baci7.default/zotero/zotero.sqlite
This is the correct Zotero directory to back-up, the data directory. That is, ~.zotero/zotero/[hashnumber].default/zotero/*. This directory was a few hundred MB. As for the application directory, why back it up at all? Download and install the latest version of Zotero instead.

Restoring

First, install the Zotero app, either the old one or the latest version. If it's a new install it will create a new folder in your home directory: ~.zotero/zotero/[newhashnumber].default/zotero/. Open and close Zotero a couple times to be sure the install is clean. Then just take the old data directory (you backed-it up above) and overwrite the new data directory. Your new structure will be something like ~.zotero/zotero/[newhashnumber].default/zotero/[old backed-up data]. The next time I opened Zotero, my backed-up citations were there.

Connect to browsers (optional)

You can manually enter Zotero entries. Browser plug-ins make it easier for some online sources. But after a back-up, the connector between stand-alone Zotero and its browser plug-ins, may or may not be broken. Once the standalone is working and up-to-date, start Zotero and then go to the links for the connector that matches the browser you like. Here's a couple of them.

Chromium
Chromium Zotero Connector

Opera
Opera Zotero Connector

Saturday, September 29, 2012

EXIF data, renumbering, cropping, rotating (lossless)

Links: ExifTool :: "rename" command notes :: PDF merging

A common activity is stripping annoying JPEG EXIF data and/or renumbering shots into a reasonable schema. Of course, pulling the EXIF, say with imagemagick, typically means reducing the file quality, since any program which opens a JPG slightly reduces its quality. As for renaming, for many users, this means the prospect of a Perl or Bash script which includes the mv command.

Instead, most batch stripping and renaming can be done without a script. Two CLI applications exiftool and rename handle most situations.

renumbering

A typical problem is a set of files with the same prefix, say, "blue", but a mixture of places in their numbers. So, eg, "blue9.jpg", "blue109.jpg", "blue43.jpg". To put these in order, we want the same number of digits, say three digits. We want blue009.jpg, blue043.jpg and blue109.jpg(as-is). Suppose we have hundreds of these files. We could write a script, but are there simple commands instead? Yes. In a terminal, cd to the folder with the files and:

$ rename blue blue00 blue?.jpg
The one question mark locates the one digit file, and adds two zeros. This means blue9 will be changed to blue009. What about the two digit file, blue43.jpg? We only need to add one zero to files with two digits:
$ rename blue blue0 blue??.jpg

Now we have blue043.jpg. This is the template for any numbering system: decide on a number of digits and then one or two commands should manage it.

Exif - ExifTool

Available at the link at top. Easily extracts, writes, deletes EXIF data. I don't even recall compiling, I think all I had to do was move a copy of into /usr/bin or some such. Maybe I had to compile.

ExifTool can do several actions, but this post concerns stripping EXIF data for all photos in a directory. Go to that directory, filled with JPG files:
$ exiftool -all= *.jpg
Or, if you have exiv2 and want to losslessly remove IPTC, XMP, and EXIF data...
$ exiv2 -d a *.jpg

Renaming

Go to the directory with the files and use the rename command. Let's say they all start with "IMG" and then some number. To rename them to "Cam01_" in a numbered sequence:
$ rename IMG Cam01_ IMG*

Done.

Cropping

Scanning in 150 lines typically makes a 1256x1752 image. If I forget to set the scan size, the bottom 110 lines just show the scanner bed. To get rid of this excess, copy those JPG's (or use the originals if you don't mind them being changed) into a directory and:

$ mogrify -crop 1256x1642+0+0 *.jpg

The 0+0 is the offset, in other words the image will begin in the top left corner(0,0) and go 1256 pixels horizontally and 1642 vertically. Similarly, if I scan at 75 lines, I get a 624x877 and typically crop down to 624x822.

Rotating

$ jpegtran -rot 90/270 -trim infile.jpg > outfile.jpg

..."90" and "270" being degrees cw rotation. Eg, use "270" for 90° ccw rotation. "Trim" drops edge pixels which can't properly rotate. Also jpegtran doesn't appear to allow wildcards -- if that's correct, a script is necessary for batches with it. Thus, for lossless batching, I use mogrify after cd'ing into that folder. Eg, for 90° ccw...

$ mogrify -rotate 270 *.jpg

add OCR layer

This makes a scanned PDF searchable. Recognition is not 100%

$ yay -S ocrmypdf

pdf conversion

Edit - 2016: ImageMagick (like most apps) has become less and less intuitive to the average user over the years. 1) users should now specify "compress" to avoid a PDF file 10 times larger than the sum of the JPGs being concatenated. 2) users should attempt to match density to the scanned density. The size of the resulting PDF file in megabytes does not change due to density (unlike "compress"), but the size of the page inside the reader does change. If your scans were at 200 DPI, but your density is 100, the page size will be 2x size in the PDF browser and will not match well if concatenated with other docs:

$ convert *.jpg -compress JPEG -density 200 somefile.pdf

A rough yardstick for the density number is to use what you'd want for say, "dpi", on a printer. If one wants to change the page orientation to landscape, then add: -rotate 90 . There's more on all this here. At the bottom of that page is a link to yet a more elaborate page, etc etc.

policy file modification

In 2019, an ImageMagick security vulnerability apparently developed during conversion, such that conversion was de-authorized. To fix: change "none" to "read|write", or "all", in /etc/ImageMagick-6/policy.xml, or to the latest version, 7 or 8. The change must be in the "policymap" portion of the file. Once it's fixed, it may remain that way for a year or two but may eventually be overwritten during an update and need to be re-accomplished.

# nano /etc/ImageMagick-7/policy.xml
<policy domain="coder" rights="all" pattern="PDF,PS" />

The effect is immediate and requires no restart or logout. Any older versions still on the disk, eg version 6, will have zero effect on the current version.

Prior to 2013, ImageMagick's "convert" automatically read the density from the JPG, as well as auto-detected the compression format. A much simpler command was performed in those days:

$ convert *.jpg somefile.pdf

Concatenate/extract PDF pages

Combining several PDF's into a larger PDF (common with letter attachments) is best with GhostScript. Imagine the first input file is in1, second in2, etc...
$ gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=out.pdf in1.pdf in2.pdf

To cleanly extract one or more pages from a PDF, use Ghostscript to avoid the rasterization of extracting as a JPG:
$ gs -sDEVICE=pdfwrite -dNOPAUSE -dBATCH -dSAFER -dFirstPage=22 -dLastPage=36 -sOutputFile=outfile.pdf 100p-inputfile.pdf

Once a PDF page is isolated, make it into a reasonably clean JPG for editing.
$ convert -colorspace RGB -resize 800 -interlace none -density 300 -quality 90 input.pdf someoutput.jpg

However, in this final "convert" command, one is liable to encounter the XML security policy which requires the recommended changes noted above to /etc/ImageMagick-7.xml. The changes must go inside the "policymap" section to be effective.

evince pdf reader

Evince is a reliable gnome-based reader, however it has a incomprehensibly stupid flaw: Evince requires that gvfs be installed to display a sidebar index in the PDF. Nothing related to file systems and volume management should have been made a dependency for an application that displays PDFs. PDF readers are not file managers and can easily internally index themselves for a sidebar without an external indexer, especially an intrusive configuration and memory hog like gvfs. I now use "Okular". The interface is not as nice looking but works as well generally and without gvfs.

Sunday, November 13, 2011

pdfedit - pdf's etc (FAIL)

Links: sourceforge - pdfedit   www.boost.org   Xournal

Like most blog posts, this one is born from annoyance. My current rage was with PDF books retreived from Project Gutenberg. Typical PDF book files should be a few hundred K and fast to load. Some are. Some are several MB and also open quickly. But a few are several megabytes and, while loading, push one's CPU to an unhealthy 100% for minutes, instead of for a few seconds. This subset of larger PDF's are of course impossible to open on portable devices. The problem is the Gutenberg volunteers make a normal PDF, but then add a 1200 lines of resolution photo of the book's cover to the first page of the PDF. It takes a lot of CPU and memory for PDF software to simultaneously render a huge photo down to a tray icon, display the huge photo full-screen, and load the first few pages of text. The fix is to edit such PDF's initial page, reducing the first page photo to a typical 75 or 150 lines of resolution photo.

So these PDFs need repairing or else one's CPU will need replacing, but is there a Linux program out there which does this? We can say "yes" definitively if we want to spend hundreds on the Adobe Acrobat solution. And there are well-proven Linux tools like pdftotext that quickly extract all the PDF's text unformatted. But what about a Linux program that just opens the PDF, allows us to edit, and then close the file? Based on this ideal, I decided to give PDFedit a shot.

installation (v.0.4.5)

Comes as a .bz2 because they have decided to pander to the Windows crowd, apparently. The README indicates "Boost" is the dependency. Boost is just a set of C++ libraries, so I ran configure before doing any checks to see if they might already be installed. Nope:
checking for boostlib >= 1.20.0... configure: error: We could not detect the boost libraries (version 1.20 or higher). If you have a staged boost library (still not installed) please specify $BOOST_ROOT in your environment and do not give a PATH to --with-boost option. If you are sure you have boost installed, then check your version number looking in . See http://randspringer.de/boost for more documentation.

boost (v.1.47) installation

PDFedit's pretension of requiring Boost is annoying. For example, 1) C++ libraries sufficient for compiling are already on people's systems, we don't need a redundant set, 2) installing them means bloating one's system for no reason and, worst of all, 3) they are on Sourceforge servers so add an hour to the installation timeline. (Edit: indeed, the first download was 30MB and was a set of PDF documents mislabeled as source.) A half hour was already wasted, but it's a dependency, gotta get it in. Let's go directly to the boost site to get the libraries. And...the Boost site bounced me back to Sourceforge for another 53 frigging MB at Sourceforge 60K "speeds". Installing PDFedit is starting to look like a 2 hour operation.

bootstrap

So, opened the PDFedit source. No configure file, no README. Great. Noting there are some bootstrap files however, so we're apparently dealing with frigging bootstrap. Now we have bad choices by both the Boost and the PDFedit developers. Also Boost appears to require Python. So the real dependency tree is apparently: PYTHON-->BOOST-->XPDF-->PDFEDIT
$ ./boostrap.sh
$ ./b2 --prefix=/usr
This doesn't work. I finally located some installation instructions. They're on the Boost website instead of in a simple README in the source. They appear partially inaccurate since they are without root. Let's start over and change it to a way it will work.
$ ./boostrap.sh --prefix=/usr
# ./b2 install

back to pdfedit (hours later)

I've almost forgotten why I needed to install PDFedit in the first place, but here we go. Did a mostly standard configure -prefix=/usr, however the results showed me that no tools or kernel tests would be included. Start over.
$ configure -prefix=/usr --enable-tools --enable-kernel-tests
This went well except that kernel checks couldn't be configured due to some missing package apparently called Cppunit for which it wants version 1.10 or later. Let's see if we can get that in.

Cppunit (v.1.12.1) installation

This was a standard configure -prefix=/usr, make, # make install. No problems.

back to pdfedit

Attempted 3 ways
$ configure -prefix=/usr --enable-tools --enable-pdfedit-core-dev --enable-kernel-tests
$ configure -prefix=/usr --enable-tools --enable-pdfedit-core-dev
$ configure -prefix=/usr
All of these resulted in fatal errors during make
make[2]: *** [cpagecontents.o] Error 1
make[2]: *** Waiting for unfinished jobs....
make[2]: Leaving directory `/home/foo/Download/pdfedit-0.4.5/src/kernel'
make[1]: *** [kernel] Error 2
make[1]: Leaving directory `/home/foo/Download/pdfedit-0.4.5/src'
make: *** [source] Error 2
Apparently the PDFedit source has design and documentation flaws much deeper than one can suss out in the time required for reasonable installation. On the first account, it should run with normal kernel settings. On the second account, they left the little detail of kernel recompiling out of their hard-to-locate documentation, when it should be the first thing noted. Further, the documentation neglects any information regarding which kernel switches would need to be set. So really, users would have to guess among 2,600 kernel options in order to use PDFedit. In short, PDFedit will either work on one's PC or it won't, dealer's choice. Troubleshooting using strace and finding the needle in the haystack of the entire PDFedit source, goes far beyond the investment most people should have to make to simply install a program. I certainly have more appealing things to do with two weeks.

I wasted half a day on the shiatty PDFedit product and was unable to install it or edit my PDF's. In the end, I ran pdftotext on the particular PDF I wanted to fix. I'll format that basic text file with LaTeX as I read it, and then recompile when finished -- the resultant PDF will be easily read on a portable device. This is extra work I'll first have to do with a desktop, so I guess I'll read the book at home.

Saturday, October 15, 2011

OCR with Tesseract

Links: Script which appends each JPG to a larger file :: training information

Note: for extracting text from PDF's, pdftotext is a go-to CLI tool. Can be configured for better line breaks, etc, too.
This page is based on tesseract, but others are available. Here's a quick scanning summary: Time: scan to binary JPG's at 200X200 lines. This makes output files of 600K each, but who cares, since they will be deleted. It takes about 15 seconds per JPG to OCR them. Accuracy: appears about 95%.
  1. Scan at 200x200 binary
  2. $ tesseract input.jpeg output
To append a series of JPG's into a longer text file, there is a script, or one can...
  1. Scan at 200x200 binary
  2. $ tesseract input.jpeg output
  3. concatenate the text files, if in numbered order, with...
    $ cat * > onebigfile.txt
From there, one can create a LaTeX file, etc.

tesseract installation

ARCH: # pacman -S tesseract-data-eng This will pull in English data files, and the entire tesseract program.
SOURCE: Tesseract source was at Google Code (thanks,guys), and was version 3.0 as I wrote this. Per usual, I didn't bother with reading or dependency checks, just gave it a shot.

Standard configure, make, and # make install seemed to go well, but I found on first run that it couldn't find its libraries. I strace'd and saw the wrong directories. Reaccomplished configure as...
$ configure -prefix=/usr
...and all was fine. Or so I thought. I attempted to run the program and it couldn't open the jpeg file I was using for an input. Time to return to Google code and actually go through the ReadMe, apparently.

tesseract installation pt 2

The ReadMe indicated two additional steps to the above would be required: 1) installing "Leptonica", if I wanted tesseract to OCR image files other than TIFF's (eg, jpegs) and, 2) selecting language(s) to place into /usr/share/tessdata following the build and installation.

leptonica installation

The main site for leptonica is another Google code site, but there are also many sites for users getting deeply into it as a physics analysis tool or so on. For my purposes, just downloaded the source (version 1.68 as of this writing) and performed a standard configure, make, and # make install, with the small configure modification of
$ configure -prefix=/usr

tesseract installation pt 3

With leptonica apparently in without a problem, I built tesseract again, in order to let the build process recognize that leptonica was now in place. [Again, leptonica was installed to provide tesseract with the capacity to extract text from file types (eg. jpegs), other than TIFF's.] Tesseract installed smoothly again with a standard configure, make, and # make install, again using the slight modification
$ configure -prefix=/usr

Tesseract language files were available at the same Google code site where we initially retrieved tesseract itself. I selected english and spanish (in order to demonstrate to students), but there appears to be roughly 50 languages available there. They all come as .gz files; simply unzip and then add or remove them as desired from /usr/share/tessdata (following installation of tesseract). Most of us will only need to leave the english file in there -- eng.traineddata.

tesseract summary

The program read text at 100% accuracy, from pages scanned at 300 lines in b/w, and took about 8 seconds (on my old system) per image to convert. Even adding scanning time, this should be significantly more efficient than typing speeds for most people, though maybe those in the 90+ wpm category can just retype, not sure. The installation steps in summary:
  1. Unless only using TIFF inputs (eg faxes), verify installation of leptonica before building tesseract
  2. Download tesseract source, compile and install
  3. Download language files, unpack, and move (requires root) to installed /usr/share/tessdata directory
If converting an image into English text, one needn't specify the language. It's simply...
$ tesseract inputfile.jpeg outputname
...which produces outputname.txt. For iterations, a simple script can roll through image after image.

still to come

Time permitting, I will install the OCRFeeder GUI frontend and see if that adds any pleasing advantages.

Thursday, September 15, 2011

Imagemagick - pdf, etc

A trail of crumbs about turning JPGs into printable PDFs. The key is "printable", because we can move jpgs into a pdf without any issues, but what does it take to print? Also in this post: converting PDF to JPG's (ImageMagick)

For example, suppose we have a simple two-page letter: we sign it and it's ready to mail so we scan it. We want to take the two jpgs, one for each page, and make it into a single 2-page pdf. This is trivial. Put them in a directory and
$ convert *.jpg somefilename.pdf
If this gives low quality or a too-large file, try the more recent version, which is compression specific, eg JPEG or PNG:
$ convert *.jpg -compress JPEG somefilename.pdf
We want this as close to copy quality, in case we have to print it later. Particularly so if we have a collection of handwritten notes from a class. Clarity is important.

scanning resolution

I typically don't scan at more than 75 lines, because that makes a clean copy for a jpg and it isn't unreasonably large.

merge pdf's into one

$ gs -q -sPAPERSIZE=letter -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=out.pdf a.pdf b.pdf
Using GhostScript, quality is maintained, unlike if "convert" from ImageMagick is used. ImageMagick is good for going from one file type, say jpg's, and converting to another, say pdf's. If you run it with pdf's as the input and output, quality is diminished. Other pdf merge programs are not typically installed with a distro, but can be added...eg, pdftk and pdfconcat.

PDF to JPG

I have a multiple page PDF and I want to break it out into individual. Sometimes I can get away with 75 lines, but it works much cleaner at 150:
$ convert -density 150 some.pdf %d.jpg
And out they come.

Sunday, December 20, 2009

LaTeX hijinx

links
latex forum  TexLive install (zenwalk)   TeX Live guide   summary of commands   general guide   general guide  latex basics   latex basics   formatting   formatting tips   font info  more font   equations   graphing information  graphing instructions   photos/graphics   complex graphs   tables  lines, boxes  templates: letters, tables  BibTeX   BibTeX  Hongzhi's Notes   convert latex to png


Note: If Perl or Tk version problems appear running tlmgr or tlmgr -gui, it might be searching on the DVD instead of the HDD installation. The way to confirm this is to run $ tlmgr update --list which will attempt to evaluate what packages could be updated by examining the database. If it comes back unable to find the database and the folder is the DVD, not the HDD, update where it looks:
$ tlmgr option location http://mirror.ctan.org/systems/texlive/tlnet
Also update tlmgr, before checking anything else.
$ tlmgr update --self



Latex

Unlike MS Word, LaTeX is not WYSIWYG, but we it's features are transparent,non-proprietary, and configurable to very fine grain. LaTeX seems slightly ungainly initially, before one understands what set of binaries they will typically use. One becomes more efficient as they learn, but the easiest approach for a noob appears to be to download a complete 2.8 GB TexLive or MiKTeX iso, that has all potential binaries and many templates. Just burn it to DVD and then install it to the hard-drive from the DVD. One will avoid encountering missing binary requirements by having a complete installation. The greatest advantage of the basic LaTeX being in ASCII text is that it is easily searchable w/grep, unlike proprietary formats (eg. Word). Additionally, publishers often produce .cls files which automatically, or nearly automatically, format one's text for the style of the journal's submission requirements. After placing in the appropriate directory, one only need change one line at the top of their document eg: \documentclass{theircls}.

tex files
The basic LaTeX file is the ascii .tex file. It can be edited with any text editor. Once complete, the source .tex is compiled into a .dvi file (device independent), but it can also be compiled into other formats, such as .pdf, .ps, .ep, etc.

tex file syntax
The default settings for margins are huge, around 2" in every direction. In the basic .tex file below, I added {geometry} package information to overcome this but, if the default geometry is desired, {geometry} can be deleted. One can create their own style sheets and call them with \usepackage, applying desired behavior across any document, similar to the way a css sheet does in an html document.

test.tex
% percents are comments
\documentclass[letterpaper]{article}
\usepackage[left=3cm,top=3cm,right=3cm,nohead,nofoot]{geometry}
\usepackage[british]{babel}
% \usepackage[T1]{fontenc} accents, umlauts, etc
% \usepackage[utf8]{inputenc} chinese characters
% \usepackage{graphicx} if photos
% \usepackage{indentfirst} indents first para in section
% \usepackage[scaled]{helvet} sans serif pt1
% \renewcommand*\familydefault{\sfdefault} sans serif pt2
\author{\LaTeX Newbie}
\title{A Quick Example}

\begin{document}
\section{Notes Wk 1}
Math 674 -- Spring 2010
\subsection{20100116 Introduction}
We review the syllabus and introductions. A primary concern seems to be the use of a calculator.\\

Here are a couple of equations that are pretty well known, the second being the quadractic formula. I'm uncertain how to make a larger space between the two equations:
\begin{displaymath}
E = mc^2
\begin{array}{*{20}c} {x = \frac{{ - b \pm \sqrt {b^2 - 4ac} }}{{2a}}} &
{{\rm{when}}} & {ax^2 + bx + c = 0} \\ \end{array}
\end{displaymath}
\noindent
Just a short follow-up text
\end{document}

If we then compiled it into a .pdf with the command, say $ pdflatex test.tex , it looks like this:



graphs and photos
Many people creates graphs or plots of equations outside LaTeX and "\include" the results, while also using a package to process it. The main packages are eepic, graphicx, and tikz. Eepic is not known to work with pdflatex, which I use to compile my docs into PDF files. It appears a simple way is to use gnuplot from the command line, and export the resulting graph as an *.eps file. In the main document, use the graphicx package ("\usepackage {graphicx}") and then, where graphics are desired, call the eps file(s) using \includegraphics with the file name to insert the graphic. Graphicx can also import jpgs pngs and the like, as described in this wiki primer.

Another option is tikz, which is actual vector graphics. The package is \usepackage{tikz}, and then the callout is \begin{figure}, which is apparently the graphics area. Nested, we use \begin{tikzpicture} with associated code then entered to create the graph. Tikz apparently is a user application layer for a program called "pgf". The info on pgf along with some typical tikz examples is available at the pgf site. Chapter 12 of the TIKZ manual there is particularly helpful for mathematics graphing, but does not manage equations and smooth curves easily. It is possible, and looks clean, as seen here.

currency symbols inside math mode
Since dollar signs are a special operator used to delimit math mode, suppose we need actual dollar signs to display in a math output? Unfortunately, the only answer I've found to date is to insert: \text{\$}

tex to html, open office, word
Link: Geico Caveman's attempt
In TexLive, tex4ht appears worthless. For straight html, I didn't find anything better than $ htlatex foo.tex . this created an html document and associated css stylesheet that properly rendered math and text. At least in Firefox. The css stylesheet was bulky for a css and a few features will not parse, notably dfrac.

combining multiple documents
I can't write it any better than this excellent post for combining multiple .tex files into a book or other larger document.