Showing posts with label references. Show all posts
Showing posts with label references. Show all posts

Tuesday, November 08, 2011

Building ElectricSheep on Fedora 16 (and enabling in KDE4)

UPDATE: Apparently these steps also work on Fedora 17. Moreover, if you use Gnome3, there are some additional instructions that can help you get ElectricSheep setup.
Quick link: Updated makeSheepFedora16.sh install script
A while back, I wrote a post summarizing how to get ElectricSheep running on Fedora 15 with KDE 4.6.5. Today, I "upgraded" to Fedora 16 and was surprised to find that library updates were incompatible with ElectricSheep. Symbol mismatches made it impossible to simply symlink old shared libraries to new shared libraries. Moreover, the version of electricsheep that built fine on Fedora 15 would not build on Fedora 16.

So I made some modifications to Tait Clarridge's script to fix the build. My hacks seem to work for me so far; hopefully they do not introduce regressions into the already old version of electricsheep.

So to get ElectricSheep running on your Fedora 16 system, try downloading and running my modified makeSheepFedora16.sh script. As a bonus, it (hopefully) will install ElectricSheep as a screensaver if you are running KDE. However, the same DPMS caveats about mplayer from old post still apply until Fedora updates their mplayer to a recent version (why does it take these people so long?).

Wednesday, August 31, 2011

Electric Sheep on KDE 4.6.5 with Fedora 15 (using Intel graphics card)


This post begins with a few important updates; scroll down to see the bulk of the original post.

Fedora 16 update: If you are using Fedora 16, then see updates from a newer post about how to get ElectricSheep built and running.

DPMS Update (getting monitors to sleep/standby/suspend/turn off on schedule again): It turns out that electricsheep is preventing my monitors from getting DPMS sleep/standby/off signals because of a bug in mplayer that was fixed today in SVN r34074. If you pull down the updated mplayer and build it yourself, your DPMS problems with electricsheep will be fixed. If you aren't willing to pull down the SVN source and build the fixed binary, you could use something like this sample electricsheep-wrapper script that starts both electricsheep and a secondary process that reads waiting times from xset q, sleeps for those times, and then issues the appropriate xset dpms force commands. To use the hack, all references to electricsheep in KDE or xscreensaver configuration files must be changed to electricsheep-wrapper and the electricsheep-wrapper script has to be installed in a directory in the PATH. Or, again, you can just wait for mplayer to get patched in your Linux distribution.

KDE update: electricsheep's SourceForge SVN includes a Desktop file for KDE, and so I've updated the stuff below to use it instead. It's probably a good idea to check out their updated SVN repository at GoogleCode to see if the support files have improved.

Multiple Monitors update: KDE will stretch one electricsheep across all of your monitors. Instead, if you want electricsheep to put a different instance on each monitor, use xscreensaver instead of kscreensaver. To do so, you'll have to follow the instructions for using xscreensaver on KDE, which are also on the xscreensaver man page. I modified step 4 to use my own custom system-level kscreenlocker that doesn't force everyone on the system to use xscreensaver. Additionally, to get electricsheep to show up in the xscreensaver-demo menu, you need to not only install the relevant electricsheep.xml file (find it in the source repo's or built it yourself), but you also have to add a line to your own ~/.xscreensaver configuration file. I don't know why the former doesn't generate the latter. On one of my machines, it does. On the other, it doesn't.

Of course, YMMV.


I installed electric sheep today because I was bored of my ASCIIQuarium KDE screensaver and not thrilled about the other options (some of which bail out on my dual screen Intel setup). [ If you're not familiar with Electric Sheep, you should check out the Electric Sheep Wikipedia page which discusses how the screensaver evolves over time. It's a distributed computing project, and the genetic algorithm that guides the evolution actually takes input from Electric Sheep users (well, not me, because I don't have the keyboard support to "up" and "down" the sheep I see). So the screen saver is constantly downloading and processing new AVI's, generating new content, and contributing it back to the network. I like it because it's pretty screen saver diversity at the cost of a few computing cycles and some disk space. ] It wasn't so bad, but it also wasn't trouble free. Here's what I did (which almost worked entirely without me having to do anything special):
  1. Use the Fedora-specific script from Tait Clarridge's page on downloading and installing electric sheep in Fedora (if you are running Fedora 16, see my updated script instead).
  2. Learn from Giulio Guzzinati about the need to add an electric sheep KDE Desktop file to get the screensaver into the KDE Screen Saver configuration tool.
Unfortunately, Giulio Guzzinati's desktop file didn't work for me, and so I had to build my own use the desktop file inside the electricsheep distribution. Here the file that ended up "working" for me (which is downloadable as electricsheep.desktop, but I copied from electricsheep.desktop.kde in the SVN repo).
[Desktop Entry]
Exec=electricsheep
Icon=kscreensaver
Type=Service
X-KDE-ServiceTypes=ScreenSaver
TryExec=xscreensaver
Actions=InWindow;Root;Setup;
X-KDE-Category=Fractals Screen Savers
X-KDE-Type=xv
Name=ElectricSheep

[Desktop Action Setup]
Exec=electricsheep-preferences
Name=Setup...

[Desktop Action InWindow]
Exec=electricsheep -window-id %w
Name=Display in Specified Window
NoDisplay=true

[Desktop Action Root]
Exec=electricsheep -window-id %w
Name=Display in Root Window
NoDisplay=true

X-Ubuntu-Gettext-Domain=desktop_kdeartwork
As explained in Giulio Guzzinati's post, you can place that file in
/usr/share/kde4/services/ScreenSavers/
You can probably put it in
~/.kde/share/services/ScreenSavers/
as well (you might have to create that directory first) if you'd rather do something local. That put the Electric Sheep across both of my monitors. If you'd rather put a separate electricsheep in each monitor, use xscreensaver instead of KDE's screen saver. If you're having trouble getting your monitors to go to sleep while electricsheep is running, then you need to get an updated mplayer that fixes the bug that causes that problem (see the updates at the top of this post for more information). Alternatively, you can use a hack like this electricsheep-wrapper script to re-enable DPMS-like timeouts during the screensaver. To use the hack, all references to electricsheep in KDE or xscreensaver configuration files must be changed to electricsheep-wrapper and the electricsheep-wrapper script has to be installed in a directory in the PATH. However, it probably won't be too long until the mplayer DPMS fix reaches your Linux distribution.

Tuesday, September 23, 2008

Fixing natbib: Adding tie between author and citation

Something that bugs me about natbib is that \citet puts a formal SPACE between the authors and the citation list, and so LaTeX like...
. . . as discussed by \citet{SK86}.
that shows up near the end of a typeset line can turn into
as discussed by Stephens and Krebs
[1].
Not only does this put a number at the beginning of a line, which is a typography no-no when you aren't starting a numerical item in a list, but it separates the citation list from its neighbors. If natbib would just us a TIE (~ in TeX) instead, then the "Krebs" in the example above would never get separated from the "[1]."

The best solution is to fix natbib so that this character is configurable. That would really help when using superscript references because you could get rid of the character all together (right now superscripts get a space before them, and that looks a little silly (especially when superscripts show up on the next line!)). However, that could take a while to get fixed (CTAN isn't quite SourceForge)... So I put together the following fix, which should work OK for \citet, \citet*, \Citet, and \Citet* regardless of how many optional arguments (0, 1, or 2) are present.

(note: the \makeatletter and \makeatother commands are not needed if these lines are put into a .sty file or in a natbib.cfg file (in the same directory as your TeX document source).
% Unfortunately, natbib does not TIE textual 
% references to their citations. So authors
% sometimes get separated from citations when
% they come at the end of the line. The following
% lines attempt to fix this problem.
%
% The lines below do the equivalent of . . .
%
% \renewcommand\citet[1]%
% {\citeauthor{#1}~\citep{#1}}
%
% but they handle the star and capitalization and
% optional argument cases too.
%
% (the \makeatletter and \makeatother are not needed if
% these lines are put into a .sty file or in a natbib.cfg
% file)
\makeatletter
%
%%% These lines test for star and number of arguments
%%% and call the workhorses below
%
% Test for star (mid-sentence and start-sentence forms)
\def\citet{\@ifstar{\citetstar}{\citetnostar}}
\def\Citet{\@ifstar{\Citetstar}{\Citetnostar}}
%
% No star found. Now test for argument count.
\def\citetnostar%
{\@ifnextchar[{\squarecitet}{\simplecitet}}
\def\squarecitet[#1]%
{\@ifnextchar[{\twocitet[#1]}{\onecitet[#1]}}
\def\Citetnostar%
{\@ifnextchar[{\squareCitet}{\simpleCitet}}
\def\squareCitet[#1]%
{\@ifnextchar[{\twoCitet[#1]}{\oneCitet[#1]}}
%
% Star found. Now test for argument count.
\def\citetstar%
{\@ifnextchar[{\squarecitetstar}{\simplecitetstar}}
\def\squarecitetstar[#1]%
{\@ifnextchar[{\twocitetstar[#1]}{\onecitetstar[#1]}}
\def\Citetstar%
{\@ifnextchar[{\squareCitetstar}{\simpleCitetstar}}
\def\squareCitetstar[#1]%
{\@ifnextchar[{\twoCitetstar[#1]}{\oneCitetstar[#1]}}
%
\makeatother
%
%%% The following actually do the \cite work
%
% The \citet cases (no arg, one arg, and two args)
\def\simplecitet#1%
{\citeauthor{#1}~\citep{#1}}
\def\onecitet[#1]#2%
{\citeauthor{#2}~\citep[#1]{#2}}
\def\twocitet[#1][#2]#3%
{\citeauthor{#3}~\citep[#1][#2]{#3}}
%
% The \citet* cases (no arg, one arg, and two args)
\def\simplecitetstar#1%
{\citeauthor*{#1}~\citep{#1}}
\def\onecitetstar[#1]#2%
{\citeauthor*{#2}~\citep[#1]{#2}}
\def\twocitetstar[#1][#2]#3%
{\citeauthor*{#3}~\citep[#1][#2]{#3}}
%
% The \Citet cases (no arg, one arg, and two args)
\def\simpleCitet#1%
{\Citeauthor{#1}~\citep{#1}}
\def\oneCitet[#1]#2%
{\Citeauthor{#2}~\citep[#1]{#2}}
\def\twoCitet[#1][#2]#3%
{\Citeauthor{#3}~\citep[#1][#2]{#3}}
%
% The \Citet* cases (no arg, one arg, and two args)
\def\simpleCitetstar#1%
{\Citeauthor*{#1}~\citep{#1}}
\def\oneCitetstar[#1]#2%
{\Citeauthor*{#2}~\citep[#1]{#2}}
\def\twoCitetstar[#1][#2]#3%
{\Citeauthor*{#3}~\citep[#1][#2]{#3}}
Even if this problem gets fixed within natbib, it still might serve as a good example of how to deal with TWO or more optional arguments in macros...

UPDATE: For author-year citations (i.e., "Harvard style citations"), you must replace the \citep with \citeyearpar. That is, replace the final section of the code above with this section:
%%% The following actually do the \cite work
%
% The \citet cases (no arg, one arg, and two args)
\def\simplecitet#1%
{\citeauthor{#1}~\citeyearpar{#1}}
\def\onecitet[#1]#2%
{\citeauthor{#2}~\citeyearpar[#1]{#2}}
\def\twocitet[#1][#2]#3%
{\citeauthor{#3}~\citeyearpar[#1][#2]{#3}}
%
% The \citet* cases (no arg, one arg, and two args)
\def\simplecitetstar#1%
{\citeauthor*{#1}~\citeyearpar{#1}}
\def\onecitetstar[#1]#2%
{\citeauthor*{#2}~\citeyearpar[#1]{#2}}
\def\twocitetstar[#1][#2]#3%
{\citeauthor*{#3}~\citeyearpar[#1][#2]{#3}}
%
% The \Citet cases (no arg, one arg, and two args)
\def\simpleCitet#1%
{\Citeauthor{#1}~\citeyearpar{#1}}
\def\oneCitet[#1]#2%
{\Citeauthor{#2}~\citeyearpar[#1]{#2}}
\def\twoCitet[#1][#2]#3%
{\Citeauthor{#3}~\citeyearpar[#1][#2]{#3}}
%
% The \Citet* cases (no arg, one arg, and two args)
\def\simpleCitetstar#1%
{\Citeauthor*{#1}~\citeyearpar{#1}}
\def\oneCitetstar[#1]#2%
{\Citeauthor*{#2}~\citeyearpar[#1]{#2}}
\def\twoCitetstar[#1][#2]#3%
{\Citeauthor*{#3}~\citeyearpar[#1][#2]{#3}}
Those lines seem to work for me.

Monday, July 09, 2007

\cref* and \crefrange*: temporarily disable cleveref hyperlinks

UPDATE: I've e-mail chatted with the author of cleveref, and it sounds like the changes below (the * macros and the new defaults) may get built into the next release. So that's exciting. The author has recently sent me new versions of cleveref that include these suggestions. Only time will tell when it's on CTAN. So that's exciting.

I've also had a chance to reflect on the poorman option of cleveref. It's an interesting idea. When loaded with this option, cleveref will generate a sed script that the author can use on the source files that will change each of the cleveref macros into old-fashioned references with everything typed out. That is, if you have a journal that does not support cleveref, you run sed on your source code before uploading it, and your journal works with the resulting files that are stripped of cleveref code. That's pretty clever.

I think that by the 1.0 version of cleveref package, it will be ready to replace hyperref's \autoref macro.

One thing that hyperref gives you that cleveref does not are starred versions of the referencing commands that disable hyperlinks. For example, in hyperref, \ref* and \autoref* work exactly like \ref and \autoref but are not hyperlinked. That's nice. Of course, there is no \Autoref or \autorefs or \Autorefs.

A major nice thing that cleveref does is let you format your expanded references with more detail than hyperref. For example, you can make an equation reference expand as "Equation (1)" where the "1" gets linked while having a figure reference expand as "Fig. 1" with the whole "Fig. 1" linked. Of course, this assumes that you've loaded both cleveref and hyperref, like this:
\usepackage{hyperref}
\usepackage[hyperref]{cleveref}
Additionally, cleveref does give the equivalent of those special versions of \autoref. cleveref supports single and multiple references, including reference ranges.

So consider the following, which gives you all the nice stuff about cleveref but also adds starred versions of its macros:
\makeatletter

% \cref and \cref*
\let\origcref\cref
\newcommand{\crefstar}[1]
{\begin{NoHyper}\origcref{#1}\end{NoHyper}}
\renewcommand{\cref}{\@ifstar{\crefstar}{\origcref}}

% \crefrange and \crefrange*
\let\origcrefrange\crefrange
\newcommand{\crefrangestar}[2]
{\begin{NoHyper}\origcrefrange{#1}{#2}\end{NoHyper}}
\renewcommand{\crefrange}
{\@ifstar{\crefrangestar}{\origcrefrange}}

% \Cref and \Cref*
\let\origCref\Cref
\newcommand{\Crefstar}[1]
{\begin{NoHyper}\origCref{#1}\end{NoHyper}}
\renewcommand{\Cref}
{\@ifstar{\Crefstar}{\origCref}}

% \Crefrange and \Crefrange*
\let\origCrefrange\Crefrange
\newcommand{\Crefrangestar}[2]
{\begin{NoHyper}\origCrefrange{#1}{#2}\end{NoHyper}}
\renewcommand{\Crefrange}
{\@ifstar{\Crefrangestar}{\origCrefrange}}

\makeatother
So there you go! That nearly beats \autoref!

Why nearly? Unfortunately, cleveref breaks some Springer journal document classes. The author also doesn't claim that it does or does not support item labels (he mentions that it may or may not, so it's uncertain). Finally, I don't like the default choices for some of the label formats. For example, you shouldn't ever start a sentence with an abbreviation, and the parentheses that go around equation numbers should be surrounded by \textup to keep them from looking silly in an italicized theorem environment. That's why I'm saying that by the 1.0 version (it was 0.6 since June of 2007), it should be a pretty awesome package... especially if the modifications above are built into the package.