Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

As pointed out in this question, in TeXShop there is no way to make source paragraphs (i.e. long lines with no hard wraps) follow source indents automatically, that is, while typing. The solution proposed in the accepted answer is unsatisfactory, in my opinion, as it requires manual insertion of line breaks at every single line... I believe you should not be forced to adopt such a behavior in year 2011, unless you are a big fan of old typewriters.

My ultimate goal is to obtain

readable, "programming language-style" source code, with indented blocks for environments,

and I would like to get that using TeXShop (I know that's easy using other editors, such as Emacs). My question is:

is there at least a way to obtain such a formatting after typing, e.g. using a macro which inserts line breaks in the right spots?

The first thing I tried is the following:

  1. Write the code naturally, with no indents nor hard wraps;
  2. Select any block (or even the whole code) and then apply Source > Wrap Lines > Hard Wrap from TeXShop's menu;
  3. Select any block you want to indent, and indent it using the appropriate command in the Source menu.

However this does not work nicely, because after you indent the block some lines may become too long for the editor window's width.

share|improve this question
    
Hello and welcome. Don't use the > for emphasis or summary—it's for quotes. –  Matthew Leingang Apr 25 '11 at 1:42
1  
@Matthew: Eh, it's fine. It calls attention to the important bits. –  TH. Apr 25 '11 at 8:13
    
@TH.: It breaks the semantics of the page because the content is put inside a <blockquote> HTML element (suppose a style sheet is used to put giant quotation marks around this block?). Also, I think questions that use this kind of emphasis can be rewritten in a more readable manner without it. –  Matthew Leingang Apr 26 '11 at 14:03
1  
@Matthew: The use of > for emphasizing questions is recommended in MathOverflow's how to ask page. (MO is another StackExchange-based forum I'm using). –  fudo May 6 '11 at 10:37
2  
Hmph. OK, I'll stop complaining, but I still disagree. –  Matthew Leingang May 6 '11 at 15:24

3 Answers 3

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:

  1. collects all marked text,
  2. passes it on to Textwrangler
  3. where the text is properly aligned and broken
  4. 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
share|improve this answer
    
interesting solution, thanks! I'll give it a try. Meanwhile, I should probably add my own answer, describing the way I've coped with this issue so far… –  fudo Jul 7 '11 at 12:55
    
Hard wraps are a problem when you want to edit your source afterwards and for diff and version control programs like hg or svn –  Kit Aug 20 '11 at 12:00

TeXShop's macro editor is very powerful, so if you can write a script to pretty-print your code you can hook it into a macro and run it whenever you want.

But the best thing is probably to get in touch with the developers.

share|improve this answer
    
Thanks for your answer! –  fudo May 6 '11 at 10:14
    
I guess I could write such a macro, but I was actually looking for some "ready-to-go" solution in order to save time :) Also, TeXshop developers don't seem to take this issue into serious consideration. –  fudo May 6 '11 at 10:27

So far the best I've found is the following, rather pedestrian, solution: follow the same steps described in the question, adding:

1.5: Resize the source window in TeXShop, reducing its width by about the size of 2 or 3 indents;

2.5: Resize the window to its original width.

This avoids the problem described in the last sentence of the question.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.