I not sure what exactly is your required feature, but maybe the following will
satisfy you.
I make use of another program to do the work, namely Textwrangler, to properly
align and insert hard line breaks.
Here is a macro that does the following:
- collects all marked text,
- passes it on to Textwrangler
- where the text is properly aligned and broken
- the result is pasted back in TexShop in place of the marked text.
I apply the macro using an assigned keyboard shortcut.
I am no Applescript whizkid, so I guess the macro can be improved.
--Applescript
-- Script to transfer the current TeXShop document to TextWrangler
-- Ido Ben-Zvi
-- Based on Ramon Figueroa-Centeno's macros
tell application "TeXShop"
try
activate
set posPath to path of the front document
--return posPath
tell application "System Events" to keystroke "c" using {command down}
tell application "TextWrangler"
activate
tell application "System Events"
keystroke "a" using command down
keystroke "v" using command down
keystroke "a" using command down
end tell
hard wrap selection of text window 1 limit character width width 80 indentation none with paragraph fill and relative
--copy selection of text window 1
--set modified_text to selection of text window 1
tell application "System Events" to keystroke "c" using {command down}
--close myTeXfile
end tell
-- back at TexShop
activate
--set modified of front document to yes
--paste
tell application "System Events"
keystroke "v" using command down
end tell
on error
beep
end try
end tell
--tell application "TextWrangler"
-- close POSIX file FILEPATH
--end tell
I don't think there are many standard styles of coding outside the world of C/C++ and languages with C-like syntax. In fact, the styles you named in the questions are all C styles. I cannot recall any named styles for lua, PHP, Lisp, etc. There certainly are styles widely used for many languages, but except for C/C++, you can hardly find any "style guides".
TeX, whose syntax is quite unique, does not really has a style. It is perhaps even impossible to define a style in my opinion. For example, in C, someone (I think it is Linus) once said if your code has three or more nested levels, then you should redesign it. However, for TeX, it is not uncommon for a math formula to have many levels of brackets and one needs to deal with those long formulas, i.e., how to break them into lines, where to align them, etc. It is hard to define clear rules to be applied for all situations in the TeX world.
But readability of the code is still very important: this is the reason styles were invented in the first place. In my experience, alignment is perhaps the most important tool to improve the readability of TeX code. In fact there are tools, for example the Align plugin for Vim, available to make this task easier. And indentation is just as important to TeX as it is in other languages. I just don't think it is better to define a consistent rule for all TeX code. Instead, I believe TeX is more close to human languages and requires us to improve its readability based on the context.
Best Answer
Yes, it is possible. Spaces at the begin of source lines is always ignored by TeX. However, I disagree that it is more readable for a normal document. Having several paragraphs of a, say
\subsubsection
indented by many spaces is not really readable to me. Instead I normally add certain separation lines before the sectioning commands, like 80-120x%
. You can use two or more of them for higher sectioning commands. Multiple chapters and parts should be not in one source file anyway, IMHO, but instead split over several files which are then included in the main document using\include
or\input
.If you question is actually about how to do this automatically then note that this is of course editor dependent. I don't know any editor which does that for sectioning commands. It might be possible to configure the more advanced ones, but for that we would need to know which one you are using.