Document Classeshow to use or create custom counters via another alphabet

Information and discussion about specific document classes and how to create your own document classes.
Post Reply
mturan
Posts: 14
Joined: Wed Nov 10, 2010 10:01 pm

how to use or create custom counters via another alphabet

Post by mturan »

I have been busy creating a thesis style for my college in Turkey. Our regs push us use Turkish alphabet in various places like page numbering (appendix), sectioning, enumerating. As you all may now, we are restricted to use arabic, roman, Alph and alph by default. We have 29 letters in our alphabet. Just to cut it short, is there any way to use our alphabet as a counter? can we create something like \Alphtr{counter} or \alphtr{counter}? if yes how please? Thanks in advance

MTURAN


http://www.turkishlanguage.co.uk/alphabet.htm link of turkish alphabet

Turkish character codes, I used in cls file
% Turkce Karakter Kodlari

\catcode240=13 \def ğ{\u g}
\catcode231=13 \def ç{\c c}
\catcode246=13 \def ö{\"o}
\catcode254=13 \def ş{\c s}
\catcode252=13 \def ü{\"u}
\catcode253=13 \def ı{{\i}}
\catcode221=13 \def İ{\.I}
\catcode199=13 \def Ç{\c C}
\catcode208=13 \def Ğ{\u G}
\catcode214=13 \def Ö{\"O}
\catcode222=13 \def Ş{\c S}
\catcode220=13 \def Ü{\"U}
Last edited by mturan on Sat Nov 13, 2010 12:02 am, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

nlct
Posts: 276
Joined: Thu Nov 06, 2008 11:15 am

how to use or create custom counters via another alphabet

Post by nlct »

The definition of \alph is:

Code: Select all

\newcommand\alph[1]{%
  \expandafter \@alph \csname c@#1\endcsname
}

\newcommand\@alph[1]{%
  \ifcase #1%
  \or a\or b\or c\or d\or e\or f\or g\or h\or i\or j\or
  k\or l\or m \or n\or o\or p\or q\or r\or s\or t\or u\or 
  v\or w\or x\or y\or z\else \@ctrerr
 \fi
}
You can adapt this by replacing "a", "b" etc with the Turkish equivalents. (You'll need to add some extra \or parts to go up to 29.)

Regards
Nicola Talbot
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

how to use or create custom counters via another alphabet

Post by localghost »

Let me translate Nicola's suggestion into code. As she already mentioned, you can derive and equivalent definition for your needs. I once did something similar for a »greek« numbering some time ago [1]. See code below for a new \turkish and \Turkish numbering macro.

Code: Select all

\documentclass[11pt,a4paper,english]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{blindtext}

\makeatletter
\newcommand*{\turkish}[1]{%
  \expandafter\@turkish\csname c@#1\endcsname
}
\newcommand*{\@turkish}[1]{%
  \ifcase#1\or a\or b\or c\or \c{c}\or d\or e\or f\or g\or \u{g}\or h\or i%
    \or \i\or j\or k\or l\or m\or n\or o\or \"{o}\or p\or r\or s\or \c{s}%
    \or t\or u\or \"{u}\or v\or y\or z%
    \else\@ctrerr\fi
}
\newcommand*{\Turkish}[1]{%
  \expandafter\@Turkish\csname c@#1\endcsname
}
\newcommand*{\@Turkish}[1]{%
  \ifcase#1\or A\or B\or C\or \c{C}\or D\or E\or F\or G\or \u{G}\or H\or I%
    \or \.{I}\or J\or K\or L\or M\or N\or O\or \"{O}\or P\or R\or S\or \c{S}%
    \or T\or U\or \"{U}\or V\or Y\or Z%
    \else\@ctrerr\fi%
}
\makeatother

\begin{document}
  \pagenumbering{Turkish}

  \Blinddocument
\end{document}
These new numberings can be used as known from the default ones (\roman, \Roman, …). If you are using the enumitem package, it may require some further additions in the preamble to make the package aware of the new definitions. But we can handle that occasionally.

[1] View topic: greek letters as page numerals?


Best regards and welcome to the board
Thorsten
mturan
Posts: 14
Joined: Wed Nov 10, 2010 10:01 pm

how to use or create custom counters via another alphabet

Post by mturan »

Beeing a part of community is a great feeling Thorsten and Nicola, thanx for that :). I kinda mixed up what you guys replied and came up with the solution. I tried the first code and it worked for me now, but the second code might be replaced in enumitem.sty in between line 225 through 229 for the second solution as a future reference for the people who want use both eng and tr alphabet selectively. I will be on with more questions and more friends. Again thanks for on time on target replies.

Best Regards
MTURAN

Code: Select all

\renewcommand\alph[1]{%
  \expandafter \@alph \csname c@#1\endcsname
}

\renewcommand\@alph[1]{%
  \ifcase #1%
  \or a\or b\or c\or \c{c}\or d\or e\or f\or g\or \u{g}\or h\or i%
    \or \i\or j\or k\or l\or m\or n\or o\or \"{o}\or p\or r\or s\or \c{s}%
    \or t\or u\or \"{u}\or v\or y\or z%
    \else \@ctrerr
\fi
}
\renewcommand\Alph[1]{%
  \expandafter \@Alph \csname c@#1\endcsname
}

\renewcommand\@Alph[1]{%
  \ifcase #1%
  \or A\or B\or C\or \c{C}\or D\or E\or F\or G\or \u{G}\or H\or I%
    \or \.{I}\or J\or K\or L\or M\or N\or O\or \"{O}\or P\or R\or S\or \c{S}%
    \or T\or U\or \"{U}\or V\or Y\or Z%
    \else \@ctrerr
\fi
}

Code: Select all

\AddEnumerateCounter{\arabic}{\@arabic}{0}
\AddEnumerateCounter{\alph}{\@alph}{m}
\AddEnumerateCounter{\Alph}{\@Alph}{M}
\AddEnumerateCounter{\roman}{\@roman}{viii}
\AddEnumerateCounter{\Roman}{\@Roman}{VIII}
\AddEnumerateCounter{\Turkish}{\@Alphtr}{R}
\AddEnumerateCounter{\turkish}{\@alphtr}{r}
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

how to use or create custom counters via another alphabet

Post by localghost »

mturan wrote: […] I tried the first code and it worked for me now, but the second code might be replaced in enumitem.sty in between line 225 through 229 for the second solution as a future reference for the people who want use both eng and tr alphabet selectively. […]
It is not necessary (and anything but recommendable) to modify the package file itself. Just put those lines into the preamble of your document and it will work.

Code: Select all

\AddEnumerateCounter{\Turkish}{\@Turkish}{R}
\AddEnumerateCounter{\turkish}{\@turkish}{r}
Now that the problem is solved, please be so kind and mark the topic (not the last post) accordingly as clearly written in Section 3 of the Board Rules (to be read before posting) and as you have already been directed. Please keep that in mind for the future so that further reminders will not be necessary.


Thorsten
mturan
Posts: 14
Joined: Wed Nov 10, 2010 10:01 pm

Re: how to use or create custom counters via another alphab

Post by mturan »

Good call Thorsten, thanks for the heads up.
Post Reply