<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>TeXShop</title>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <style type="text/css" media="screen">@import "v1.css";</style>
</head>

<body>

<!-- title and menu -->
<div id="header">
 </div>



<!-- main content -->
<div id="main">

<center><h2>TeXShop on macOS Golden Gate</h2></center>

<h3>Compiling TeXShop on Golden Gate</h3>

Compiling code on Golden Gate requires a new version of XCode, version 27.0 beta. That version automatically adds the latest version of Liquid Glass to the program. A couple of days ago,
Apple released macOS 27.3, the latest beta. This document describes that release,  and compiling code on it using XCode 27.3 beta.


<p>Initially the Tahoe source code for TeXShop 5.57 refused to compile on Golden Gate.
The first bug reported was that the minimal version of macOS which the code would support was Sonoma rather than the previously supported Big Sur and higher. The latest XCode
only supports Sonoma, Sequoia, Tahoe, and Golden Gate. So this item was reset to Sonoma.

<p> After that, a long list of errors were reported, all related to calls to various forms
of [customView frame]. The problem was that many different classes defined such
a frame element and XCode couldn't determine which should be called. This problem was
fixed by revising a few lines of code in TSToolbarController.m. In makeToolbarItemWithItemIdentifier,
the change was

<pre>

else {
        /*
	[toolbarItem setMinSize:NSMakeSize(NSWidth([customView frame]), NSHeight([customView frame]))];
	[toolbarItem setMaxSize:NSMakeSize(NSWidth([customView frame]), NSHeight([customView frame]))];
         */
        [toolbarItem setMinSize:NSMakeSize(20.0, 20.0)];
        [toolbarItem setMaxSize:NSMakeSize(400.0, 400.0)];
    }

	return toolbarItem;
   }
</pre>

and in makeToolbarItemFixedWithItemIdentifier the similar change was 

<pre>
{
    NSToolbarItem*    toolbarItem = [self makeToolbarItemWithItemIdentifier:itemIdent key:itemKey];
    [toolbarItem setView: customView];
    /*
    [toolbarItem setMinSize:NSMakeSize(NSWidth([customView frame]), NSHeight([customView frame]))];
    [toolbarItem setMaxSize:NSMakeSize(NSWidth([customView frame]), NSHeight([customView frame]))];
    */
    [toolbarItem setMinSize:NSMakeSize(20.0, 20.0)];
    [toolbarItem setMaxSize:NSMakeSize(400.0, 400.0)];
    
    return toolbarItem;
}
</pre>

After these changes, only one error remained, in TSDocument.RootFile. See lines 186 - 195.
In the routine CheckRootFile, a number of lines had to be commented out, as shown below.

<pre>
} else if (task == RootForOpening) {
			// added by Terada (from this line) // This was moved here for version 2.40
			/*
             if([SUD integerForKey:DocumentWindowPosModeKey] == DocumentWindowPosSave){
				NSRect activeWindowFrame = [[obj textWindow] frame];
				NSScreen *screen = [NSScreen mainScreen];
				CGFloat minX = 20 + ((NSMinX(activeWindowFrame) 
					+ NSWidth(activeWindowFrame) 
				+ 20 > NSWidth([screen frame])) ? 0 : NSMinX(activeWindowFrame));
				CGFloat minY = (NSMinY(activeWindowFrame) 
				+ NSHeight([screen visibleFrame]) 
         			- NSHeight([screen frame]) + 20 < 0) ? NSHeight([screen frame]) : 
				NSMinY(activeWindowFrame) - 20;
				NSRect newFrame = NSMakeRect(minX, minY, NSWidth(activeWindowFrame),
		 		NSHeight(activeWindowFrame));
				[[obj textWindow] setFrame:newFrame display:YES];
			}
             */
</pre>

<h3>Martin Hairer</h3>

<p> On the first day of the developer conference,
before I even downloaded the 27.0 release, Martin Hairer (martin.hairer@epfl.ch) reported
that TeXShop jumps a page each time it typesets on Golden Gate. He also reported that he could fix
this by going to line 1526 in MyPDFKitView.m and commenting out the line "visibleRet.size.height = 3;".
How he found this is mysterious to me; he has debugging skills that are beyond me! Removing this line
does not break any of the systems supported by Golden Gate and completely fixes the stability program,
so after typesetting a user is exactly at the same spot as before.

<p>Following these changes, TeXShop 5.57 compiles and runs on macOS Golden Gate. Apple notarized
it to produce a regular program with both Intel and Arm code which runs on
Sonoma, Sequoia, Tahoe, and Golden Gate. Additional Inactive Engines were added to the code,
which is now called TeXShop 5.58. TeXShop 5.58 is currently based on macOS 27.3.


<h3>Running TeXShop 5.58 on macOS Golden Gate</h3>

<p> After making these code changes, TeXShop 5.58 runs fine on Golden Gate. There are many features
to check, of course, but most work as always. In macOS 27.3, there are only two known
TeXShop bugs. The first is rather trivial; when a pdf document is first opened, the document is scrolled to the last page rather than opening on the first page. 

<p> The second bug is more serious. Both magnifying glasses draw nothing on the screen. The tool which selects a region by drawing a boundary around it also draws nothing. Finally, in a table of contents, the tool which briefly shows the item referenced by an item draws nothing. All of these items work the same way, by creating an invisible screen over the regular screen and drawing into that invisible screen. So there are three items, but only one bug.

<p> However, the selection tool shows that the code almost works. If you hold down the mouse and
select a region, a boundary is supposed to be drawn on the screen, but it is missing.
However, if you then click inside this boundary to drag the contents, that task works just as before. 


<p> Luckily, I have both a machine running Tahoe and a second machine running Golden Gate. So I copied
TeXShop 5.58 from Golden Gate to Tahoe and ran it there. To my delight, the magnifying glasses and
selection tool now worked correctly! This means that the problem is not in my code and not in
XCode 27.3, but solely a bug in the preview releases of Golden Gate. I've reported the bug to Apple.


<h3>Albert Guillen i Fabregas</h3> <albert.guillen@eng.cam.ac.uk></h3>

<p> Several weeks before the developer conference, I got an astonishing email from 
Albert Guillen i Fabregas (albert.guillen@eng.cam.ac.uk). Albert was a fan of dark mode,
and had configured TeXShop to use Skim for previewing because that program has the
amazing ability to convert preview images from black text on white to white text on black
without changing the essential color of illustrations. But Albert wondered if this
feature could be added directly to TeXShop. In these days when Artificial Intelligence
is all the rage, he didn't just wonder but found the Skim source code and then asked Claude
to produce code for the corresponding TeXShop feature. He mailed me the report from Claude,
which was a TeX source file and related pdf document dated April, 2026.

<p> This Claude report started by discussing several methods to convert images
before explaining the advantages of the approach used by Skim. The report then carefully
explained the basic method used by Skim, including tricky points. 

<p> This was followed with a section called "Proposed changes in TeXShop" containing actual
lines of code to be added to globals.h, globals.m, FactoryDefaults.plist, MyPDFKitView.h,
MyPDFKitView.m, TSTextView.m, TSPreviewWindow.h, and TSPreviewWindow.m. Many were minor
additions, but MyPDFKitView.m now contained the essential code from Skim to apply a DarkMode
InversionFilter covering the preview image. 

<p> The report ended with a description of areas that might need further testing, and then
section noting that Skim is open source and listing the key source files describing the
required filter. 

<p> Albert soon discovered that some of the code samples did not directly compile in
TeXShop, so he found the required modifications and soon had the feature working. He sent me a 
diff file for my own attempts.

<p> I should warn that my attempts to make this work were at first not as successful as
those 
of Albert. The cause is explained in a later section below. Incidentally, Skim works fine on Golden Gate, even in key areas where my initial code had problems.

If you are interested in the AI report from Claude, here are links to the LaTeX source it produced,
and the corresponding pdf output file:

<ul>
<li><a href="dark_mode_proposal.tex">dark_mode_proposal.tex</a>. </li>
<li><a href="dark_mode_proposal.pdf">dark_mode_proposal.pdf</a>. </li>
</ul>

<h3>Skim, by Christiaan Hofman, Adam Maxwell, Michael McCracken</h3>

<p>Now we come to the big guns, the guys who actually wrote the filter switching black and white 
in a pdf file displayed in dark mode, while simultaneously keeping the color of illustrations
intact. Please do not forget the people who contributed this fantastic idea to the pdf world!

<p> In TeXShop-5.58, we implement this technique in a very minimalist way. using the AI code
which copied the filter from Skim source. When the display switches to dark mode, the Skim filter is
added to the Preview Window. When the display switches back to light mode, the
filter is removed. In Skim, users can choose whether to use the filter, but in TeXShop 5.58
it happens automatically.

<p> In Skim, the dark mode filter gives the screen a rich black and white texture, while in the
original version of TeXShop 5.58, the texture was gray rather than deep black. On the other hand, the magnifying
glasses in TeXShop 5.58 did produce that deep black and white texture used by Skim. 

<p> To turn dark mode on and observe the new filter, use the standard Macintosh technique: open
System Settings and activate the Appearance Module. Click on provided icons to select Dark mode
or Light Mode. 

<p> However, there is a much easier way to make this choice. In Apple's App Store, download the
free application named Nightfall. Install this program in your Applications folder. Click it to
activate. The program adds a small circular icon to the system toolbar, half black and half white.
Click this circle to switch from Light mode to Dark mode. Click again to switch from Dark mode to
Light mode. The application thus allows you to easily switch without dealing with System Settings,
and thus to quickly test the new TeXShop feature.


<p> We have not tested the program running on Sonoma and Sequoia, the other two versions of macOS
supported by programs compiled on Golden Gate.

<h3>New Development on June 25</h3>

<p> Earlier I explained that the
dark mode filter in Skim gives a rich black and white texture, while originally in TeXShop it gave a gray
appearance. 

<p> Shortly after originally posting this page, I got a response from Martin Hairer. He pointed out that
the Themes section of TeXShop Preferences has an option which sets the background color
of the Preview Window. This can be done in both Light mode and Dark mode. 

<p> Hairer suggested that the gray appearance
of the Skim filter inside TeXShop is due to this setting rather than to any code from Skim.
So I commented out the line of code which can set the background color of the TeXShop Preview window. This immediately gave the rich black and white texture of Skim without changing
any Skim code in TeXShop. Hairer strikes again! 

<p> Therefore TeXShop-5.58-GG available below produces the correct rich black and white
texture used by Skim.

<p> Just to be clear, the program TeXShop-5.58-GG has two current bugs on macOS 27.3,
but if the program is simply copied to Tahoe, macOS 26, the bugs vanish and all of the features including the magnifying glasses and dark mode work correctly.

         
<h3>Downloading TeXShop 5.58 and Its Golden Gate Source Code</h3>

<p>Below are links to version 5.58 of TeXShop, and its source code when compiled on macOS 27.3.
A link is also provided to a folder named ShortSample, which contains a short one page
TeXShop project. Drag Sample.tex from this folder and drop it on TeXShop. TeXShop will open
a source window showing Sample.tex, a preview window showing Sample.pdf, and two illustrations.
The new macOS Golden Gate will actually display magnified images for this short project,
but the images are drawn in incorrect spots.


<ul>
<li><a href="TeXShop-5.58-GG.zip">TeXShop-5.58-GG.zip</a>. </li>
<li><a href="TeXShop-5.58-GG-Source.zip">TeXShop-5.58-GG-Source.zip</a>. </li>
</ul>

<ul>
<li><a href="TeXShop-5.58-GG-ShortSample.zip">TeXShop-5.58-GG-ShortSample.zip</a>. </li>
</ul>



<br>
<br>
<br>




</div>


</body>
</html>