GeneralIs the command loaded?

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
zaradek
Posts: 22
Joined: Fri Jun 27, 2008 9:49 pm

Is the command loaded?

Post by zaradek »

How can I get to know weather \usepackage[magyar]{babel} give out the \frenchspacing command or not without studying the contents of magyar.ldf?

Is it possible to write a check for things like this in the tex code?

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
User avatar
Juanjo
Posts: 657
Joined: Sat Jan 27, 2007 12:46 am

Is the command loaded?

Post by Juanjo »

Try this:

Code: Select all

\documentclass{article}

\usepackage[czech,magyar,french,spanish,english]{babel}

\makeatletter
\newcommand{\IsFrenchspacingOn}{\ifnum\the\sfcode`\.=\@m Yes \else No \fi}
\makeatother

\begin{document}

Is french spacing on?

English: \IsFrenchspacingOn

\selectlanguage{spanish}
Spanish: \IsFrenchspacingOn

\selectlanguage{french}
French: \IsFrenchspacingOn

\selectlanguage{magyar}
Magyar: \IsFrenchspacingOn

\selectlanguage{czech}
Czech: \IsFrenchspacingOn

\end{document}
The CTAN lion is an artwork by Duane Bibby. Courtesy of www.ctan.org.
zaradek
Posts: 22
Joined: Fri Jun 27, 2008 9:49 pm

Re: Is the command loaded?

Post by zaradek »

Thank you! It is cool.

Could you explain the "\the\sfcode`\.=\@m" condition?

Actually I don't know how to programme macros in latex. I was googling for some answers, but I couldn't find so much information about it. Could you recommend some material about programming latex?

Thanks, Máté
User avatar
Juanjo
Posts: 657
Joined: Sat Jan 27, 2007 12:46 am

Is the command loaded?

Post by Juanjo »

zaradek wrote: Could you explain the "\the\sfcode`\.=\@m" condition?

Actually I don't know how to programme macros in latex. I was googling for some answers, but I couldn't find so much information about it. Could you recommend some material about programming latex?
Let me explain how I arrived to the above code, since that will answer your first question and will give some hints about the second. I first opened the doc of babel. It is in your hard disk: type "texdoc babel" in the command line or search in somewhere like /usr/local/texlive/2008/texmf-dist/doc/generic/babel; if not, look here. I went to the magyar section and searched "frenchspacing". This directed me to an instance of "frenchspacing"... in the Czech language. There I learned that languages activate or deactivate frenchspacing through the \bbl@frenchspacing command. So I searched it. This command appears in Section 12.6, defined as follows:

Code: Select all

\def\bbl@frenchspacing{%
\ifnum\the\sfcode‘\.=\@m
\let\bbl@nonfrenchspacing\relax
\else
\frenchspacing
\let\bbl@nonfrenchspacing\nonfrenchspacing
\fi}
And voilà the origin of the test I showed in my first post. Moral of the story (up to now): A good way to learn writting code is to read code. Many packages are well documented, as are the kernel LaTeX macros (for the latter, search locally in .../texmf-dist/doc/latex/base/source2e.pdf or look in CTAN).

At first, I didn't understand the \sfcode and \@m commands. I searched them in a good book on Plain TeX. In addition to the TeX book, by D. Knuth, there exists the excellent manual TeX by Topic, by Victor Eijkhout, freely downloadable. The \@m macro is just an internal abbreviation of 1000. The \sfcode of a character is a number related with the amount of space that TeX should leave after it. The sfcode of punctuation signs is 1000, if frenchspacing is active, and greater otherwise. So the trick, in your problem, consists in testing if the sfcode of . (point) is 1000 or not.

In different posts, I've cited more resources to learn programming LaTeX (here and here, for example). The moderators and other contributors also often do so. Read their posts, you'll learn a lot!
The CTAN lion is an artwork by Duane Bibby. Courtesy of www.ctan.org.
zaradek
Posts: 22
Joined: Fri Jun 27, 2008 9:49 pm

Re: Is the command loaded?

Post by zaradek »

Thank you very much! It was a great help. :)
Post Reply