\documentclass{article} \newcounter{c@LastPage} \usepackage{lipsum} \usepackage{atveryend} \begin{document} a %\lipsum %\lipsum \makeatletter \AfterLastShipout{\immediate\write\@auxout{\string\setcounter{\string c@LastPage} {\thepage}}} \ifnum\value{c@LastPage}>2 foo \fi \makeatother \end{document}
Thursday, June 28, 2012
Getting the total number of pages into a counter
This is the only way i know of, to get the total number of pages for anything other than mere display. Took me two hours to get just right and requires two packages. There is a surprising lot of packages that do similar things but in the end all just print. Weird. Enjoy
"The save failed due to out of memory or disk space".
I had a friend come over with her new Mac because when writing a thesis Word (2007?) claimed "The save failed due to out of memory or disk space". Given that the disk had more space left over than mine ever had (>200Gb), something else had to be wrong. Different Volumes didn't do the trick, permissions were ok, the folder wasn't dangling.
Turns out she used a feature from the equation editor that was incompatible with the .doc format and would have needed to save as .docx. Way to go Microsoft - I hereby proclaim you most useless and moronic error message producer of this month.
Turns out she used a feature from the equation editor that was incompatible with the .doc format and would have needed to save as .docx. Way to go Microsoft - I hereby proclaim you most useless and moronic error message producer of this month.
Saturday, June 9, 2012
Wrap list around a figure
I often had a need for a way to wrap a list around a figure in the past and hadn't quite found out. Wrapfig and floatflt aren't compatible with lists and break the layout in very bad ways.
Approaches with 2 minipages or tabulars are just wrong, period. There is a new package called cutwin, that you can combine with parshape (or use it without) to coerce your text to do something similar to what ultimately wrapfig should do. I didn't get it to work properly with my ams doc, which is kind of sad. I get the feeling their way of building lists is incompatible with the rest of the latex world :/.
Then i found a solution in some mean way to use minipage. It was still wrong because the type area is so different with ams but after a bit of fiddling with my stuff this works:
\begin{wrapfigure}{r}{.3\textwidth}
\centering
\includegraphics[width=.29\textwidth]{pic}
\end{wrapfigure}
\item[ad d)]
\end{minipage}
\end{enumerate}
Looks really wrong, but does the right thing. Hope this helps someone. I sure would have liked to find this.
Approaches with 2 minipages or tabulars are just wrong, period. There is a new package called cutwin, that you can combine with parshape (or use it without) to coerce your text to do something similar to what ultimately wrapfig should do. I didn't get it to work properly with my ams doc, which is kind of sad. I get the feeling their way of building lists is incompatible with the rest of the latex world :/.
Then i found a solution in some mean way to use minipage. It was still wrong because the type area is so different with ams but after a bit of fiddling with my stuff this works:
\begin{enumerate}
\item some text
% Rest of old \item
\par
% New \item starts here!
\noindent\begin{minipage}{.88\textwidth}\begin{wrapfigure}{r}{.3\textwidth}
\centering
\includegraphics[width=.29\textwidth]{pic}
\end{wrapfigure}
\item[ad d)]
\end{minipage}
\end{enumerate}
Looks really wrong, but does the right thing. Hope this helps someone. I sure would have liked to find this.
A Proof list enumerated by Arrows
Up until recently i used
or description instead of enumerate which looks even worse. Both don't exactly look right, are cumbersome to type and threw warnings about missing fonts, because latex tried to set the math in bold, so today i sat down and wrote the solution:
Not only does it work and is cooler, it looks better and is less work to type. Nice!
\begin{enumerate}
\item[``$\RightArrow$"]
\item[``$\LeftArrow$"]
\end{enumerate}
or description instead of enumerate which looks even worse. Both don't exactly look right, are cumbersome to type and threw warnings about missing fonts, because latex tried to set the math in bold, so today i sat down and wrote the solution:
\def\ProofDirection#1{\expandafter\@ProofDirection\csname c@#1\endcsname}
\def\@ProofDirection#1{\ensuremath{\ifcase#1\or\Leftarrow\or\Rightarrow \else\@ctrerr\fi}}
\def\RevProofDirection#1{\expandafter\@RevProofDirection\csname c@#1\endcsname}
\def\@RevProofDirection#1{\ifcase#1\or {$\Rightarrow$}\or {$\Leftarrow$}\else\@ctrerr\fi}
\newcounter{pcounter}
\newenvironment{myprooflist}[1][]{%
\ifx\relax#1\relax
\let\@show@count\ProofDirection
\else
\let\@show@count\RevProofDirection
\fi
\begin{list}{\hss\llap{\textup{``\@show@count{pcounter}''}}}{\usecounter{pcounter}}
}{
\end{list}
}
Sunday, April 15, 2012
gentoo on the samsung 900x3a - the tricky parts
I installed gentoo about two months ago on my shiny new samsung 900x3a, most things work out of the box but some don't.
If you have an error 2 you likely have /usr/src/linux/ pointing to a kernel that isn't the one you are running.
This will make the scancodes known to udev.
The next step is create a rule in /lib/udev/rules.d/95-keymap.rules.
This file serves to match the laptop to the keyboard, i.e. in our case it finds a samsung 90x3a and will then load the file we created earlier. This is not triggered right now, to activate them now run:
This will tell you the device name for your keyboard, in my case event5
Kernel module
To make it work first build a custom kernel module created by Corentin Chary (iksaif) . As of 3.3.1 it hasn't made it to mainline yet, although it is scheduled for inclusion. Make sure you have a recent kernel emerged, symlinked, built and installed.
su -
cd /usr/src/
git clone https://github.com/iksaif/samsung-laptop-dkms
cd samsung-laptop-dkms
make
make install
modprobe samsung-laptop
If this works without errors then
depmod -aIf you have an error 2 you likely have /usr/src/linux/ pointing to a kernel that isn't the one you are running.
Udev Rules
Enter the following into
/lib/udev/keymaps/samsung-90x3a
0x96 kbdillumup
# Fn+F8
0x97 kbdillumdown
# Fn+F7
0xD5 wlan
The next step is create a rule in /lib/udev/rules.d/95-keymap.rules.
ENV{DMI_VENDOR}==
"[sS][aA][mM][sS][uU][nN][gG]*"
, ATTR{[dmi
/id
]product_name}==
"90X3A"
, RUN+=
"keymap $name samsung-90x3a"
grep -A 2 keyboard /proc/bus/input/devices | grep Sysfs
/lib/udev/keymap input/event5 /lib/udev/keymaps/samsung-90x3a
Now these new rules should be loaded, check that you can see them by running xev in a terminal emulator in X. If you press Fn+F8, then you should see events. If you don't see any, then it isn't working.
More to come...
More to come...
Tuesday, April 10, 2012
python initializers
I just got bitten by this, so let's share. I wanted to be lazy about initializing an array of 250 by 250 values and wrot e cache = [[-1]*250]*250. This unfortunately gave the wrong results later on, because the inner arrays are just pointers to one object, thus all 250 arrays inside are the same. Try for yourself
Conclusion:
Be very careful when using these "new" lazy style initializers!
>>> a = [[0]*2]*2
>>> a
[[0, 0], [0, 0]]
>>> a[0][1] = 1
>>> a
[[0, 1], [0, 1]]
>>> a
[[0, 0], [0, 0]]
>>> a[0][1] = 1
>>> a
[[0, 1], [0, 1]]
Be very careful when using these "new" lazy style initializers!
Sunday, April 1, 2012
MacOS Lion and Dashboard widgets on the desktop
A friend of mine just got a new mac and under macos lion it's apparently more difficult than before to get dashboard widget onto the desktop. To enable them disable launchpad as spaces, do
and logout and login again. Then goto the dashboard (F12 usually), hold the widget and go back to the desktop (F12 again).
defaults write com.apple.dashboard devmode YES
and logout and login again. Then goto the dashboard (F12 usually), hold the widget and go back to the desktop (F12 again).
Subscribe to:
Posts (Atom)