Thai script

The Thai script is the writing system used to write the Thai language. It is an abugida and brahmic script, which means that vowel markings must be attached to a consonant letter. The consonants are always written in order from left to right, but vowels have rules where it must be written to the left, right, top, or bottom of the first consonant in each syllable.
An example of this will use the Thai consonant k to show where the following vowel must be written.
Spaces are not used to set words apart, but sentences and clauses. Punctuation markers are not normally used. For example, the sentence "I like to eat fried rice, but she likes to eat pad thai" would be written in Thai as chanch`bkinkhaawphad aeteth`ch`bkinphadaithy. If one were to place spaces in between each word (which Thai does not do), it would be written as chan ch`b kin khaaw phad aet eth` ch`b kin phad aithy.
History
The writing system was based on the Old Khmer Script, but it made changes because the Old Khmer Script did not show tones, which was an important part of the Thai language. To make the writing system suitable for the Thai language, the Thai script added new letters and tone markers that would show the tone of a word. It was the first known writing system in the world to show the tones of a word. Even though the Chinese writing system existed before the Thai script was invented and that Chinese was a tonal language at that time, there was no writing system that could show the tones of Chinese words until much later. The first time Chinese would be written using the Latin alphabet and tone markers was the Portuguese-Chinese dictionary written by Matteo Ricci and Lazzaro Cattanero written around the 16th century.
Letters
Thai has 44 consonant letters, 32 vowel markers and combinations, and 4 tone markers. This makes the total amount of letters in Thai 80, one of the largest out of any sound-based writing system used for a living language. Despite having so many consonant letters, the number of consonant sounds is actually far fewer, with 21 consonant sounds. For example, the "th" digraph used in RTGS, which would be the aspirated alveolar stop (written as [th] in IPA), can be written in six different ways: th,th,th,th,th, or th. This is because the letters used in the word will decide what tone a word has and whether or not the words are loanwords.
Thai has five tones, mid, high, low, rising, and falling, and the reader is supposed to figure out what tone a syllable has based on the consonant class, whether it is a live syllable (meaning that it ends with a voiced consonant or long vowel) or a dead syllable (meaning that it ends with a voiceless consonant or a short vowel), and whether the vowel is long or short. When a syllable has a tone marker, different rules must apply alongside the ones already written above.
Thai borrowed some letters from loanwords of Sanskrit and Pali. Many of those letters sound or sounded differently in the languages they came from, but they now have the same pronunciation as other Thai sounds. Letters borrowed from Sanskrit and Pali are only used to write those same loanwords from those same languages.
Spelling vs. pronunciation
Thai words have a complicated relationship between spelling and their pronunciation. Many of the letters today have different sounds than when they were first used. While many Thai words have tone markers that show the tone of a word, many do not. However the word will still have a tone, and for words that do not have tone markers, one can still figure out the tone by the class of consonant (high, middle, or low), whether the syllable is a live or dead, syllable, and the length of the vowel. While the different classes of consonants made different phonemes, or distinct sounds, in the past, they now are set apart by which tones the words have.
Other difficulties include silent letters and consonant mutations. For silent letters, the word chanthra (written as cchanthr in Thai) would be pronounced chan when spoken. Notice that the suffix -thra, written as thr in Thai, is missing in the phonetic spelling. That is because the Thai spelling is based on the Sanskrit spelling of the word, the language where the word comes from. Many loanwords in Thai are based on the spelling rules of the language they came from rather than their Thai pronunciation. Also, Thai words cannot end in any consonant that is not a nasal consonant, semivowel, or voiceless stop, the final consonants that are not either one of those mutate so that they can become pronounceable in Thai. For example, the word wat (meaning "temple") is spelled as wad (written as wad in Thai), but since -d, or d, is a voiced alveolar stop, it must be pronounced as the voiceless alveolar stop -t. Also, the name Bhumibol (written as phuumiphl in Thai) is pronounced as Phumiphon. The alveolar lateral approximant -l ,or l, must be pronounced as the alveolar nasal -n. The English loanword bus (written as bas in Thai) is pronounced bat in Thai. The voiceless alveolar fricative -s , or s, must be pronounced as the voiceless alveolar stop -t.