Are spelling, punctuation and capitalization part of grammar?
Solution 1:
It depends on whom you ask. "Grammar", like "linguist", "weight", or "fruit", is a term that doesn't have a single perfectly defined meaning. It may have a somewhat specific meaning in certain contexts, but not in isolation.
The OED gives a longer definition (which is from 1900, so not entirely current, but I think it can be trusted to describe the usage at that point in history):
That department of the study of a language which deals with its inflexional forms or other means of indicating the relations of words in the sentence, and with the rules for employing these in accordance with established usage; usually including also the department which deals with the phonetic system of the language and the principles of its representation in writing. Often preceded by an adj. designating the language referred to, as in Latin, English, French grammar.
with a note including the following observations:
As above defined, grammar is a body of statements of fact—a ‘science’; but a large portion of it may be viewed as consisting of rules for practice, and so as forming an ‘art’. The old-fashioned definition of grammar as ‘the art of speaking and writing a language correctly’ is from the modern point of view in one respect too narrow, because it applies only to a portion of this branch of study; in another respect, it is too wide, and was so even from the older point of view, because many questions of ‘correctness’ in language were recognized as outside the province of grammar: e.g. the use of a word in a wrong sense, or a bad pronunciation or spelling, would not have been called a grammatical mistake. At the same time, it was and is customary, on grounds of convenience, for books professedly treating of grammar to include more or less information on points not strictly belonging to the subject.
Until a not very distant date, Grammar was divided by English writers (following the precedent of Latin grammarians) into Orthography, Etymology, Syntax, and Prosody, to which Orthoëpy was added by some authors. All these terms (except Syntax) were used more or less inaccurately (see the several words). The division now usual is that into Phonology, treating of the sounds used in the language, Accidence, of the inflexional forms or equivalent combinations, and Syntax, of the structure of sentences; the branch of grammar dealing with the functions of the alphabetic letters is usually treated along with the phonology.
(As I said, the entry is from 1900, so the description of the "division now usual" is a bit out-of-date. "Accidence" as far as I know is no longer used, and seems to refer mainly to what would now be called "morphology".)
So the idea that writing has something to do with the word "grammar" is fairly old, and obviously many people continue to have this idea today—not necessarily as a scientific viewpoint, but just as part of their general way of speaking.
A number of present-day linguists (according to the meaning of that word as used by linguists, language scientists, rather than the somewhat common—and older—alternative general meaning people who know a lot of languages) object to the broadest uses of the word "grammar". See the following blog post overview by Arnold Zwicky: It’s All Grammar. Zwicky explains the reason for the objection as follows:
why do people think of such a diverse collection of phenomena (check out Mary Newton Bruder in “It’s all grammar, one more time”, for an extreme case) as constituting a natural category?
(link added)
It's unclear to me to what extent linguists have been successful at promoting the use of their preferred technical definition of "grammar" by lay folk, but the recency of the linked blog posts seems to indicate that many continue to use the word in ways that linguists would not prescribe.
Solution 2:
In a comment, John Lawler wrote:
No. Spelling, punctuation, and capitalization are all part of writing. Writing is not language -- it's the representation of language, which is spoken. In real (i.e, spoken) language there is no spelling, no punctuation, and no capitalization. But there is grammar; the OED definition is correct, because it refers to spoken language.. English grammar applies to the language, whether it's written or spoken; but spelling, punctuation, and capitalization are strictly for writing. Just modern technology, not grammar.